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.

47 lines
2.6 KiB

4 years ago
  1. # ICallbacks
  2. An interface for receiving callbacks when running tests. All test runs invoke the callbacks until the next domain reload.
  3. The `RunStarted` method runs when the whole test run starts. Then the `TestStarted` method runs with information about the tests it is about to run on an assembly level. Afterward, it runs on a test fixture level and then on the individual test. If the test is a [parameterized test](./https://github.com/nunit/docs/wiki/Parameterized-Tests), then it is also invoked for each parameter combination. After each part of the test tree have completed running, the corresponding `TestFinished` method runs with the test result. At the end of the run, the `RunFinished` event runs with the test result.
  4. An extended version of the callback, [IErrorCallbacks](./reference-ierror-callbacks.md), extends this `ICallbacks` to receive calls when a run fails due to a build error.
  5. ## Public methods
  6. | Syntax | Description |
  7. | ---------------------------------------------- | ------------------------------------------------------------ |
  8. | `void RunStarted(ITestAdaptor testsToRun)` | Invoked when the test run starts. The [ITestAdaptor](./reference-itest-adaptor.md) represents the tree of tests to run. |
  9. | `void RunFinished(ITestResultAdaptor result)` | Invoked when the test run finishes. The [ITestResultAdaptor](./reference-itest-result-adaptor.md) represents the results of the set of tests that have run. |
  10. | `void TestStarted(ITestAdaptor test)` | Invoked on each node of the test tree, as that part of the tree starts to run. |
  11. | `void TestFinished(ITestResultAdaptor result)` | Invoked on each node of the test tree once that part of the test tree has finished running. The [ITestResultAdaptor](./reference-itest-result-adaptor.md) represents the results of the current node of the test tree. |
  12. ## Example
  13. An example that sets up a listener on the API. The listener prints the number of failed tests after the run has finished:
  14. ``` C#
  15. public void SetupListeners()
  16. {
  17. var api = ScriptableObject.CreateInstance<TestRunnerApi>();
  18. api.RegisterCallbacks(new MyCallbacks());
  19. }
  20. private class MyCallbacks : ICallbacks
  21. {
  22. public void RunStarted(ITestAdaptor testsToRun)
  23. {
  24. }
  25. public void RunFinished(ITestResultAdaptor result)
  26. {
  27. Debug.Log(string.Format("Run finished {0} test(s) failed.", result.FailCount));
  28. }
  29. public void TestStarted(ITestAdaptor test)
  30. {
  31. }
  32. public void TestFinished(ITestResultAdaptor result)
  33. {
  34. }
  35. }
  36. ```