SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
2.1 KiB

4 years ago
  1. # How to get test results
  2. 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](./reference-test-runner-api.md) with an instance of a class that implements [ICallbacks](./reference-icallbacks.md). There are four `ICallbacks` methods for the start and finish of both the whole run and each level of the test tree.
  3. ## Example
  4. An example of how listeners can be set up:
  5. > **Note**: Listeners receive callbacks from all test runs, regardless of the registered `TestRunnerApi` for that instance.
  6. ``` C#
  7. public void SetupListeners()
  8. {
  9. var api = ScriptableObject.CreateInstance<TestRunnerApi>();
  10. api.RegisterCallbacks(new MyCallbacks());
  11. }
  12. private class MyCallbacks : ICallbacks
  13. {
  14. public void RunStarted(ITestAdaptor testsToRun)
  15. {
  16. }
  17. public void RunFinished(ITestResultAdaptor result)
  18. {
  19. }
  20. public void TestStarted(ITestAdaptor test)
  21. {
  22. }
  23. public void TestFinished(ITestResultAdaptor result)
  24. {
  25. if (!result.HasChildren && result.ResultState != "Success")
  26. {
  27. Debug.Log(string.Format("Test {0} {1}", result.Test.Name, result.ResultState));
  28. }
  29. }
  30. }
  31. ```
  32. > **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](https://docs.unity3d.com/Manual/RunningEditorCodeOnLaunch.html).
  33. 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](./reference-ierror-callbacks.md) 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](./reference-setup-and-cleanup.md) throws an exception.