Fant
Overview
Fan includes a unit test framework baked right into the runtime - it is very similar to common test frameworks such as JUnit. The key concepts for testing:
- Write test classes which subclass
sys::Test - Write test methods which start with "test"
- Assert test conditions via the "verifyXXX" methods
- Run the tests the
fantcommand line tool
Organizing Tests
By convention test classes are organized directly within their associated pod using the following directory structure:
myPod/
build.fan
fan/
ClassA.fan
ClassB.fan
test/
TestClassA.fan
TestClassB.fan
Writing Tests
Any concrete class within a pod which extends from sys::Test is considered a test class. Any method which starts with "test" in a test class is considered a test method. Test methods must be public instance methods with no parameters. Test methods assert conditions using the verify methods. Three of the most commonly used verify methods:
verify: assert a boolean condition is trueverifyEq: assert two objects are equalverifyErr: assert an exception is thrown
Here is an example of a test class:
class SampleTest : Test
{
Void testStuff()
{
verify('A'.isUpper)
verifyEq('A'.lower, 'a')
verifyErr(ParseErr#) |,| { Int.fromStr("@#!") }
}
}
Running Tests
The fant launcher is used to run tests. You can pass a pod name, type qname, or slot qname to run any test in any installed pod. You can also pass "-all" to run all tests in all pods:
fant -all fant testSys fant testSys::StrTest fant testSys::StrTest.testEach
The test results will be printed to standard out. Any test failures will be raised as exceptions.
Test Lifecycle
When running tests, each test method is executed as follows:
- A fresh instance of the test class is instantiated via
make Test.setupis called- The test method is called with no arguments
- Any exceptions raised are trapped and the test is marked failed
Test.teardownis guaranteed to be called
Any exception raised by the test method is considered a failure. Calls to verify which fail will just raise an exception.

