Before you run unit tests, you can create and register a unit test listener, which is an object that implements the
The purpose of a test listener is to determine what is done with the unit test results. For example, you can display them on a form or capture them to a file. There can be at most one test listener. If there is no test listener, test results are written to the Jade Interpreter Output Viewer window.
To present the unit test results on a form, the form must implement the
When the form loads, create an instance of the
load() updating; vars tests : ObjectArray; jtr : JadeTestRunner; begin create tests transient; tests.add(TestCalculator); create jtr transient; jtr.setTestListener(self); jtr.runTests(tests); epilog delete tests; delete jtr; end;
To capture the results of a unit test run to a file, add a class in your user schema with a reference of type
vars tests : ObjectArray; // Listener class implements JadeTestListener and has reference of type File listener : Listener; jtr : JadeTestRunner; begin create listener transient; create listener.file transient; listener.file.mode := File.Mode_Append; listener.file.fileName := "C:\UnitTests\results.txt"; create tests transient; tests.add(TestCalculator); create jtr transient; jtr.setTestListener(listener); jtr.runTests(tests); epilog delete tests; delete listener.file; delete listener; delete jtr; end;
The following methods are reimplemented by a listener object.
The start method is invoked when a unit test run begins.
The number of unit test methods to be executed is determined and passed to the method, and can be used to display progress. For example, if there are 11 unit test methods to be executed and the test listener is a form containing a progress bar, the progress bar could be initialized showing that zero (0) out of 11 tests have been carried out.
start(numberOfTestMethods: Integer);
The methodSuccess method is invoked if all assertions in a unit test method succeed. It is passed the name of the successful test method.
The method name parameter contains the fully qualified name of the unit test method in the form schema-name::class-name::method-name.
methodSuccess(testMethodName: String);
The events during a unit test run that invoke callback methods are shown in the following table.
Method | When the listener method is invoked … |
---|---|
|
After the last test method for the last JadeTestCase subclass completes |
|
Before the first test method for a JadeTestCase subclass starts or after the last test method completes |
|
If a test method completes successfully without an exception being raised or an assertion failing |
|
Before the first test method for the first JadeTestCase subclass starts |
|
If a test method results in an exception being raised or an assertion failing |
|
If a test method has the unitTestIgnore method option and is skipped |
|
For each individual assertion that succeeds, in each test method run |