Axiom comes with a built in framework for writing functional and unit tests for your application. These tests can be written globally or organized by specific prototype. A test is a function that contains a number of assertions- if all the assertions pass and no other errors occur, the test passes. Test suites are attached to the _test property of a prototype (or in the global scope for global tests). Example:
this._test = {
setup: function(){
setUpSomeStuff();
},
teardown: function(){
removeAllThatStuff();
},
_utility_func: function(){
return somethingUseful();
},
test_example: function(){
var f = this._utility_func();
Assert.assertFalse("our utility function should return falsel", f);
},
test_arithmetic_failure: function(){
Assert.assertEqual("Math should work!", 2, 1);
}
} In this example, two special functions are defined: setup and teardown. Just like in Junit, setup is run before each test function is executed, and teardown is run afterwards. These functions are optional. Any other propety of the object is considered a test case if its name starts with 'test'- here, test_example and test_arithmetic_failure will be run as tests, while _utility_func will not. A function in the suite may call any other function in the suite using 'this' as the scope.
These tests may be run either through the manage application or programmatically. To run them through the manage application, simply select the application from the list on the left and click "Run Tests". The test results will open in a new window.
Note that since test case setup/teardown methods are often destructive, it's usually a good idea to keep a seperate instance of your application around to run tests upon.
