oTest.$runsuite()

Function group Execute on client Platform(s)
oTest NO All

Syntax

oTest.$runsuite(rSelection[, pCallbackInst, cMethodName, pListener, iTimeoutMs, iTotalTimeoutMs])

Description

Runs the selected test classes, then calls cMethodName on pCallbackInst with (rSummary, lResults). Returns an error message, or empty once the run has started.

$runsuite() runs the Test Case classes chosen by a selection, one class after another, and calls you back when the run is over. It returns an error message if the run cannot start, or empty once it has started.

Each class runs as it does in the Test editor: each test runs on a new instance of the class, and the runner waits for an asynchronous test until it reports its result or times out.

The parameters are as follows:

Parameter Description
rSelection The test classes to run, as a row returned by oTest.$newselection(). An empty row runs every test class in every open library.
pCallbackInst Optional. The instance to call when the run is over, usually $cinst. It can be an object, window or other instance.
cMethodName Optional. The name of the method to call on pCallbackInst, as text. It is called with a summary row and a results list, described below.
pListener Optional. An instance that is told about the run as it goes. It needs only the methods it wants, out of those listed below.
iTimeoutMs Optional. How long each asynchronous test may take to report, in milliseconds. 0, the default, means 30 seconds. A test that takes longer is stopped and given the outcome timeout.
iTotalTimeoutMs Optional. A limit for the whole run, in milliseconds. 0, the default, means no limit, although each class is still limited to 120 seconds. When the limit is reached, the tests not yet started are reported with the outcome notRun.

For example, to run every test class tagged "smoke" in myLib:

Do oTest.$runsuite(oTest.$newselection("myLib","",kTrue,"","smoke"),$cinst,"$onTestsDone") Returns lErr
If len(lErr)
  OK message {[lErr]}
End If

When the run is over

When the run is over, the method named cMethodName is called on pCallbackInst with two parameters: a summary row and a results list. If every test is synchronous, this happens before $runsuite() returns; otherwise it happens later, when the last test finishes.

The summary row has these columns:

Column Description
ran The number of tests that ran.
passed The number of tests that passed.
failed The number of tests that did not pass: their outcome was failed, error, timeout or stopped.
notrun The number of tests that were never started, because the run was stopped or ran out of time.
classes The number of test classes in the run.
classesfailed The number of test classes that did not pass.
elapsedms How long the run took, in milliseconds.
outcome "passed" if every test in every class passed, otherwise "failed".

The results list has one line per test, with these columns:

Column Description
class The test class, written library.class.
method The name of the test method.
mode "sync" for a test that reported its result when its method returned, "async" for one that reported later by calling $sendresponse.
outcome passed, failed (an assertion failed, or the test called $adderror), error (a fatal runtime error, or the method could not be run), timeout, stopped or notRun.
elapsedms How long the test took, in milliseconds.
result The test's result, as JSON text.
errors The errors the test recorded, as a one-column list.

A test class that could not be run at all, for example because its library was closed after the run started, has one line with an empty method and the outcome error.

If you omit pCallbackInst and cMethodName, the tests still run, but nothing is called when they finish.

Following the run

pListener is told about the run by calling these methods, if it has them:

Method Called
$onSuiteStarted(lClasses) When the run starts. lClasses lists the classes it will run, in order.
$onClassStarted(cClass, lTestNames) When a class starts. cClass is written library.class.
$onTestStarted(cClass, cMethod) When a test starts.
$onTestFinished(cClass, rResult) When a test finishes. rResult has the method, mode, outcome, elapsedms, result and errors of the test.
$onClassFinished(cClass, rClassResult) When a class finishes. rClassResult has the library, class, outcome, error, elapsedms and results of the class.
$onSuiteFinished(lClassResults) When the run is over, before the callback, with one rClassResult per class.
$onRunLog(cText, iLevel) When a test, or the runner, logs a line. iLevel is a kTestLogLevel... constant.

Test Case constants

Constant Description
kTestLogLevelInfo An information message.
kTestLogLevelWarning A warning.
kTestLogLevelError An error.

One run at a time

Only one test run can be in progress at a time, whether it was started from the Test editor, the Test Suites window, code or the MCP server's execute_test tool. A second run is refused with the error "A test run is already in progress", followed by details of the run that is already in progress. The one exception is a run started directly by a test method while it executes: that run is part of the test, and goes ahead. A run started from a worker callback is refused like any other. Use oTest.$isrunning() to find out whether a run is in progress.