haXe

Writing Unit Tests

Unit Testing is simple. You create a new TestClass and add it to the MainClass. Then you create testMethods in your TestClass. Thats it. Now, if you compile and run the MainClass, all your tests should be executed.

Create new TestCase

Create a new class extending haxe.unit.TestCase and create your own test methods. Every test method name must start with test.

class TestFoo extends haxe.unit.TestCase {
    
    public function testBasic(){
        assertEquals( "A", "A" );
    }
    
}

Add new TestCase

Now you must have a main class in which you're adding your TestCase to a TestRunner.

class MyTest {
    
    static function main(){
        var r = new haxe.unit.TestRunner();
        r.add(new TestFoo());
        // your can add others TestCase here

        // finally, run the tests
        r.run();
    }
}

Compile & Execute

Save the classes in MyTest.hx. To compile the test create compile.hxml with the content:

-neko mytest.n 
-main MyTest

Now compile it on the commandline:

haxe compile.hxml

The new compiled file mytest.n can now be invoked on the commandline:

neko test.n

The result of the test:

Class: TestFoo .
OK 1 tests, 0 failed, 1 success

Ready

From here on you are able to write your own unit tests. Some test are available on subversion : https://svn.motion-twin.com/haxeUnit

version #1065, modified 2008-05-03 00:08:45 by ncannasse