Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

After testing is finished, output results...

 

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:

Code Block
themeRDark
languagejavascript
linenumberstrue
Test.outputTo("console");

A config script is available that adds the following output methods to the Test API:

MethodOutputs toNotesAPI 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()

Same as Similar to "console" but sends output to debug.

Note: The debug() output is accessed in different places depending on OS.

1.2
"host"chat()

Same as 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()

Same as 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:

Code Block
themeRDark
languagejavascript
linenumberstrue
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 AssertionTest Signal, etc., that generated the result

.message – the message associated with the result

.isComment – is the result a comment? (true or false)

Div
classbox
Availability
Status
colourYellow
titleBeta

Requires:

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

Test API

Topics:

Child pages (Children Display)
alltrue
depthall
pageTest API
excerpttrue