This AI is still in early stages of development.
Test Results
- Aubergine
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.outputTo() with the appropriate parameter, for example:
Test.outputTo("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 |
"debug" | debug() | Similar to "console" but sends output to debug. Note: The debug() output is accessed in different places depending on OS. | 1.2 |
"host" | chat() | Similar to "console" but sends output via chat messages to player 0. If chat() is not available, reverts to using "console". | 1.2 |
"log" | log() | Similar to "console" but sends output to the log file associated with the player. If log() is not available, reverts to using "debug". | 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.outputTo = { 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
)
Contents
Jump to:
Test API
Topics:
- Test() — Define a unit test and it's configuration...
- Test Modules — A test module groups one or more unit tests and provides additional lifecycle settings for those tests...
- Test.module() — Allows multiple tests to be grouped together in to modules...
- Module Lifecycle Object — Configure the lifecycle of tests in the module...
- Test Modes — Defines the mode in which a unit test is run...
- Test.ANY( ) — The most basic unit test mode...
- Test.EXPECT( ) — Causes the test to fail if it does not generate the specified number of results...
- Test.ASYNCH( ) — Causes a test to keep running until it either passes, fails or times-out...
- Test.APPEND( ) — Appends results to a specific asynchronous test session...
- Unit Tests — The unit test function, responsible for performing one or more Test Assertions...
- Test Assertions — Assertions are used to perform various tests and annotations within a unit test...
- comment( ) — Adds a comment to the test results...
- ok( ) — A simple state checking assertion...
- hasNative( ) — Assert presence of a native property on the global object...
- hasFunction( ) — Check if a context has a function property, optionally with specified number of formal parameters...
- equal( ) — A basic equality checking assertion...
- notEqual( ) — A basic inequality checking assertion...
- strictEqual( ) — A strict equality checking assertion...
- notStrictEqual( ) — A strict inequality checking assertion...
- deepEqual( ) — A deep equality checking assertion...
- notDeepEqual( ) — A deep inequality checking assertion...
- similarTo( ) — A deep similarity checking assertion...
- notSimilarTo( ) — A deep dissimilarity spotting assertion...
- Test Signals — Signals are used to prematurely terminate Unit Tests...
- REQUIRE( ) — Check whether a test or group of tests have passed. If the requirement fails, a RequireSignal will be sent which terminates the current test and marks it as failed.
- ABORT( ) — Aborts the current test, marking it as failed in the process...
- FINISH( ) — Terminates the test as if it had finished normally...
- Test Events — Events defined by Test API...
- Test Results — After testing is finished, output results...
- Test API - Dev Notes — Developer notes for this API...
- Test API - possible future direction — Rough ideas for future development...