Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Retrieve test results

Register to receive callbacks from the test runner at the start or finish of an active test run or individual test.
Read time 1 minuteLast updated 14 days ago

You can receive callbacks when the active test run, or individual tests, starts and finishes. You can register callbacks by invoking
RegisterCallbacks
on the
TestRunnerApi
with an instance of a class that implements
ICallbacks
. There are four
ICallbacks
methods for the start and finish of both the whole run and each level of the test tree.
The folliwng example shows how listeners can be set up:
Note
Listeners receive callbacks from all test runs, regardless of the registered
TestRunnerApi
for that instance.
public void SetupListeners(){ var api = ScriptableObject.CreateInstance<TestRunnerApi>(); api.RegisterCallbacks(new MyCallbacks());}private class MyCallbacks : ICallbacks{ public void RunStarted(ITestAdaptor testsToRun) { } public void RunFinished(ITestResultAdaptor result) { } public void TestStarted(ITestAdaptor test) { } public void TestFinished(ITestResultAdaptor result) { if (!result.HasChildren && result.ResultState != "Passed") { Debug.Log(string.Format("Test {0} {1}", result.Test.Name, result.ResultState)); } }}
Note
The registered callbacks are not persisted on domain reloads. So it is necessary to re-register the callback after a domain reloads, usually with InitializeOnLoad.
It is possible to provide a
priority
as an integer as the second argument when registering a callback. This influences the invocation order of different callbacks. The default value is zero. It is also possible to provide
RegisterCallbacks
with a class instance that implements
IErrorCallbacks
 that is an extended version of
ICallbacks
.
IErrorCallbacks
 also has a callback method for
OnError
that invokes if the run fails to start, for example, due to compilation errors or if an IPrebuildSetup throws an exception.

Additional resources