We all love TDD – right ?
So you’re starting a Haxe project and you need to write some tests while you develop. Well, thanks to massiveinteractive there exists a very good unit testing library that works pretty much like flexunit.
It’s called munit and can be found here
Here’s my quick start guide:
For starters we want a top level project structure that looks something like this:

inside src we would place our package folder structure, inside test we would place the test package structure mirroring our src package structure.

Now at a terminal we want to cd to our project folder and install munit if we don’t already have it.
$ haxelib install munit
Once installed we are ready to configure munit for our project.
$ haxelib run munit config
At which point we will enter an interactive configuration session that allows us to configure various folder locations…
Massive Unit - Copyright 2012 Massive Interactive. Version 0.9.2.3
Configure munit project settings
--------------------
test src dir (defaults to 'test') :
output build dir (defaults to 'build') :
report dir (defaults to 'report') :
target class paths (comma delimitered, defaults to 'src') : src
hxml file (defaults to 'test.hxml') :
resources dir (optional, defaults to 'null') : resources
templates dir (optional, defaults to 'null') :
I have used defaults for all but two of the settings: I have explictly defined the src folder, and also specified a resources folder. If your test folder or output locations are different then this is where you would configure them.
Once that is done you will find a .munit file has been created inside the top level project folder (where you ran haxelib run munit config).
The contents of the .munit file are pretty straight forward:
version=0.9.2.3
src=test
bin=build
report=report
hxml=test.hxml
classPaths=src
resources=resources
At this point you are ready to generate all the test files and the test.hxml that can be used to build and run the tests.
$ haxelib run munit gen
When we run this command our test folder will be scanned for all our test cases and the files required to run them are generated.
If we take a look at our project structure now we’ll see something like this

Note that 4 files have been generated for us: ExampleTest.hx, TestMain.hx, TestSuite.hx and test.hxml.
ExampleTest.hx can be deleted – but it serves as a useful quick reference for the correct metadata to use to when declaring test methods.
Here’s the source of ExampleTest.hx
/**
* Auto generated ExampleTest for MassiveUnit.
* This is an example test class can be used as a template for writing normal and async tests
* Refer to munit command line tool for more information (haxelib run munit)
*/
class ExampleTest
{
private var timer:Timer;
public function new()
{
}
@BeforeClass
public function beforeClass():Void
{
}
@AfterClass
public function afterClass():Void
{
}
@Before
public function setup():Void
{
}
@After
public function tearDown():Void
{
}
@Test
public function testExample():Void
{
Assert.isTrue(true);
}
@AsyncTest
public function testAsyncExample(factory:AsyncFactory):Void
{
var handler:Dynamic = factory.createHandler(this, onTestAsyncExampleComplete, 300);
timer = Timer.delay(handler, 200);
}
private function onTestAsyncExampleComplete():Void
{
Assert.isFalse(false);
}
/**
* test that only runs when compiled with the -D testDebug flag
*/
@TestDebug
public function testExampleThatOnlyRunsWithDebugFlag():Void
{
Assert.isTrue(true);
}
}
We are now ready to run our tests with this command
haxelib run munit test test.hxml
And that’s all for now. (I did say this was quick start guide.)