Unit test, project packaging, project dependency...

65 views
Skip to first unread message

Salânio Júnior

unread,
Mar 24, 2014, 10:37:25 PM3/24/14
to haxe...@googlegroups.com
Hi,

I'm a noob in Haxe, but professional programmer. I have mostly a Java/C# background, so the bias in what I want to know...

I want to create a game with openfl/haxeflixel, but added to that I want to test some utility classes, data structures, algorithms, etc.
So, how do I organize those.

In a simple Java setup, I would have two projects, the main one and a test project depending on the first. 
How do I mimic this organization in Haxe? 
I couldn't find a way of packaging (jar/dll) a project (that could be other possibility for testing). The closest was SWC, but it looks like towards Flash. 

How do I reuse a package of data structures (stack, heaps, trees, maps, etc) in other projects?

Sorry for the different subjects, but in this case they are pretty much related.

Cheers

Justin L Mills

unread,
Mar 24, 2014, 11:38:23 PM3/24/14
to haxe...@googlegroups.com
Salânio

You can create local HaxeLib's as a way of packaging parts of a project,
specifically use the test option.

http://haxe.org/doc/haxelib/using_haxelib#testing-the-package

If you use github or similar you can put the code online.

http://haxe.org/doc/haxelib/using_haxelib#installing-a-library-from-git

If you currently use SVN or Hg then maybe better to move to git I did
add a feature to support them but needs more testing before it can be
merged.

Since Haxe code is not always target specific precompiled code like jars
and swc's are not as relevant.
But for specific targets you use pe-built code as target specific eg
ndll
jars
swcs/swf
js

for some types of code you write externs
http://haxe.org/doc/js/extern_libraries

for a few targets you can also use a lib compiler switch eg

-java-lib myjar.jar
-net-lib mydll.dll
-swf-lib myswf.swf

The haxe compile tries to cache compiled code not sure how complete but
on the c++ target the first compile is much slower than subsequent ones.
Flash target is so fast you never need to worry about putting stuff in
a swc/swf. The down side of cache is that it is not such a good idea to
have a test and live project although it is common to have more than one
hxml file.

One good approach to having a different builds is to use compiler switches.

http://haxe.org/ref/conditionals

Specifically -
"You can define your own variables by using the Haxe compiler
commandline options (for example using -D mydebug):"

So you code might have a debug version with a
-D debugMakeEasy

which you can then use in the code to make game play easier for testing
some aspects, and to make it easier to get to advanced level features.

#if debugMakeEasy
lives = 10000000;
bullets = 10000000;
health = 1000000;
#else
lives = 3;
bullets = 10000;
health = 10;
#end

For structures take a look at haxe.ds ( ds = datastructures ) and also
look at the Polygonal haxelib there is good documentation online.

For unit testing maybe try munit from massive interactive?

Not sure if that answers all your questions but maybe some useful ideas,
and others may decide to clarify further some aspects, or correct
details, but it's late here so should give you some ideas to explore.


Best Justin



Salânio Júnior:

Salânio Júnior

unread,
Mar 25, 2014, 11:52:38 AM3/25/14
to haxe...@googlegroups.com
Hi Justin,

This is a great answer, thank you!

I think you nailed it in the first time, I imagined that haxelib would do the trick, but I didn't give it the proper attention.

The specific targets features are awesome too.

The conditionals for debugging looks pretty useful.

Thanks for pointing out Polygonal. That's a lot of good stuff. The ds package seems thorough and their documentation is amazing.

I have seem munit already, that looks comprehensive enough :D.

I have some doubts in this point (unit test). I've seen in the polygonal lib that they separate the project in two packages (src and test).
By default, the test package is only used in the test context? I mean, how do I know that a lot of source code in the test packages are not in the final build of my game, for instance? Like, in maven (not saying that it is good), you specify that JUnit is only used in the test context and by default config that the code in test package will not be in the final build.

Thanks!
Reply all
Reply to author
Forward
0 new messages