Introduction
In this small example a class Test contains the logic of the test itself (testMath) and the test execution (code in main).
Details
Every test fixture (method that includes one or more assertion) must be prefixed with the lower cased word "test". You can add two special functions "setup" and "teardown" that will be executed just before and after each test method. They are used to prepare and clean-up the tests environment. Test cases classes (classes that include one or more text fixture) do not have to extend/implement any special class/interface. The only condition to make them work is that they use the naming described above and that they have the "public" modifier. Assertions are made accessing the static methods of the Assert class.
Test.hx
import utest.Assert;
import utest.Runner;
import utest.ui.Report;
class Test {
public static function main() {
var runner = new Runner();
runner.addCase(new Test());
Report.create(runner);
runner.run();
}
public function new();
public function testMath() {
var i = 1;
Assert.equals(2, i + i);
}
}build.hxml
-main Test
-lib utest
-swf test.swf
The build script assumes that you have installed utest using the command "haxelib install utest". If you are using the SVN version just point to the correct path using the -cp switch.