Overview
The Test API provides some default results output methods, however you can add your own if desired.
Tip: You can trigger output using Test Events.
Outputting results
Results are output by invoking Test.sendResultsTo() with the appropriate parameter, for example:
Test.sendResultsTo("console");
A config script is available that adds the following output methods to the Test API:
Method | Outputs to | Notes | API Version |
---|
"summary" | console() | Outputs a very brief one-line summary to the console. Note: You'll need to switch to the player via Debug Menu to see their console. | 1.2 |
"console" | console() | Outputs detailed summary, a few lines at a time, to the console. Note: You'll need to switch to the player via Debug Menu to see their console. | 1.2 |
"host" | chat() | Same as "console" but sends output via chat messages to player 0. If chat() is not available, reverts to using "console". | 1.2 |
"log" | log() | Same as "console" but sends output to the log file associated with the player. If log() is not available, reverts to using "console". | Not yet implemented |
"html" | log() | Outputs results in posh HTML format to the log file associated with the player. If log() is not available, reverts to using "console". | Not yet implemented |
If you've installed Util API, the config script will automatically load as soon as the Test API is loaded. If you've not got Util API installed, you'll have to manually include "path/to/Config/Test.js" after including "path/to/APIs/Test.js".
Creating custom output methods
To create a custom output method, or overwrite one of the existing methods, you'll need to provide an object that defines the method name and the function that outputs the results:
Test.output = {
name : "example",
method: function(results, typeOf) {
// work your magic here
}
};
You can add any number of output methods this way – all of the bundled methods are defined this way.
The method function has two parameters. The results parameter is an array of objects (see below for structure) and the typeOf parameter is a reference to typeOf() (or the Test API equivalent if you've not installed Util API).
The structure of the results array is as follows:
results[<idx>] – numeric references link to module objects in the order they were defined
.modulePath – the module's path
.state – did the module pass or fail? (true
or false
)
.numPassed – how many tests passed in the module?
.numFailed – how many tests failed in the module?
.url – the URL associated with the module (if applicable)
.tests[<idx>] – numeric references link to test objects associated with the module
.testName – the name of the test
.testMode – the object defining the test mode
.name – the mode name ("ANY", "EXPECT" or "ASYNCH")
.expect – the number of expected results (if applicable)
.state – did the unit test pass or fail? (true or false)
.results[<idx>] – numeric references link to results associated with the test
.passed – did the assertion pass or fail? (true
or false
, or null
if a comment)
.expected – the expected value (if applicable)
.actual – the actual value (if applicable)
.name – the name of the Test Assertion, Test Signal, etc., that generated the result
.message – the message associated with the result
.isComment – is the result a comment? (true
or false
)