Hello,
Is it possible to run tests from a script and export the results to an XML file?
Yes, you can use the Test Runner API to run the tests from your own script, and register a listener for receiving the results at the end of the run. Then you can process the results to write them out in whatever format you want.
Thanks for the response, but something is not working right.
I have created the attached test function.
It seems like the tests are getting executed since the player enters play mode and results appear in the TestRunner Window.
But my callbacks are not getting called.
Im using unity 2020.2.5f1
static void RunTests()
{
TestRunnerApi testRunnerApi = ScriptableObject.CreateInstance<TestRunnerApi>();
testRunnerApi.RegisterCallbacks(new MyCallbacks());
Filter filter = new Filter()
{
testMode = TestMode.PlayMode
};
ExecutionSettings settings = new ExecutionSettings(filter);
testRunnerApi.Execute(settings);
}
public class MyCallbacks : ICallbacks
{
public void RunStarted(ITestAdaptor testsToRun)
{
Debug.Log("Run Started");
}
public void RunFinished(ITestResultAdaptor result)
{
Debug.Log("Run Finished");
}
public void TestStarted(ITestAdaptor test)
{
Debug.Log("Test Started");
}
public void TestFinished(ITestResultAdaptor result)
{
Debug.Log("Test Finished");
}
}
I Found the solution here: TestRunnerApi: getting callbacks for playmode tests
The Callbacks need to be reregistered after every domain reload. Using the InitializeOnLoad attribute and a static constructor to register the callbacks again did the trick.