Skip to content

Setting up a new munit project

mikestead edited this page Mar 18, 2013 · 11 revisions

1. Run config

From inside your project directory...

haxelib run munit config

2. Specify your project settings

This will configure the current directory for munit. It will prompt you for some basic information such as

test src dir (defaults to 'test') : 
bin dir (defaults to 'bin') : 
report dir (defaults to 'report') : 
hxml file (defaults to 'test.hxml') : 
class paths (defaults to 'src') : 
resources dir (optional, defaults to 'null') : 
templates dir (optional, defaults to 'null') : 

Note: resources and templates are optional directories for overriding the default html templates used by the test-runner. See examples/02_customTemplates for more details.

Alternatively, you can set each property from the command line

This approach is ideal for CI environments.

haxelib run munit config -src test/src -bin path/bin -report path/report -hxml path/test.hxml -classPaths path/src, path/lib

Any paths you don't set will use the defaults, unless they have already been set in which case they will not be changed.

You can also set the project configuration file from an external source
haxelib run munit config -file path/to/file.txt

This command will generate the specified paths (if they don't exist already).

After the command has run, your project directory should look something like this:

.munit
bin/
report/
test/
test/ExampleTest.hx
test/TestMain.hx
test/TestSuite.hx
test.hxml

.munit

This file contains the settings defined through config. It uses a simple name/value pair string format.

version=0.2.0.116
src=test
bin=bin
report=report
hxml=test.hxml
classPaths=src
resources=null
templates=null

test.hxml

This is a stub hxml file for building the tests. By default it will be generated for you when you run "munit config" and includes targets for all platforms officially supported by munit. You can edit it as necessary.

Note that the naming of the target in <target>_test.<type> filename should not be changed as it's used by munit to identify what it's running.

# Flash 9+
-main TestMain
-cp src
-cp test
-lib munit
-swf-version 9
-swf bin/as3_test.swf

--next

#Flash 8
-main TestMain
-cp src
-cp test
-lib munit
-swf-version 8
-swf bin/as2_test.swf

--next

# JavaScript
-main TestMain
-cp test
-lib munit
-js bin/js_test.js

--next

# Neko
-main TestMain
-cp test
-lib munit
-neko bin/neko_test.n

TestMain.hx

This is the generated main class for the munit test runner. It includes some specific reporting clients and functionality for running through munit.

TestSuite.hx

This is a test suite class that is generated each time the 'gen' or 'test' commands are run in munit. It automatically includes all Test classes within the current src directory.

import massive.munit.TestSuite;
import ExampleTest;
/**
 * Auto generated Test Suite for MassiveUnit.
 * Refer to munit command line tool for more information (haxelib run munit)
 */
class TestSuite extends massive.munit.TestSuite
{		
	public function new()
	{
		super();
		add(ExampleTest);
	}
}

ExampleTest.hx

This is an example test class to use as a template in your project. It includes all common metadata for setup and teardown methods, sync and async tests. See Working with Test Classes for more information