暫無描述
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.

PlayerCallbacks.cs 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine.TestRunner;
  2. using Unity.PerformanceTesting;
  3. using NUnit.Framework;
  4. using NUnit.Framework.Interfaces;
  5. using Unity.PerformanceTesting.Data;
  6. using Unity.PerformanceTesting.Runtime;
  7. using UnityEngine.Scripting;
  8. using UnityEngine;
  9. [assembly: TestRunCallback(typeof(PlayerCallbacks))]
  10. namespace Unity.PerformanceTesting
  11. {
  12. [Preserve]
  13. internal class PlayerCallbacks : ITestRunCallback
  14. {
  15. internal static bool Saved { get; set; }
  16. public void RunStarted(ITest testsToRun)
  17. {
  18. // This method is empty because it's part of the NUnit framework's ITestListener interface,
  19. // which Unity uses for running tests in the Editor. It receives a parameter "testsToRun" but
  20. // doesn't require implementation as Unity can execute tests without it. Developers can add
  21. // custom initialization logic if needed.
  22. }
  23. public void RunFinished(ITestResult testResults)
  24. {
  25. Saved = false;
  26. }
  27. public void TestStarted(ITest test)
  28. {
  29. // This method is called by Unity when a new test has started. It receives a parameter "test"
  30. // which contains information about the test being executed. Developers can add custom logic
  31. // in this method, such as logging or setup code for the test.
  32. }
  33. public void TestFinished(ITestResult result)
  34. {
  35. // This method is called by Unity when a test has finished executing. It receives a parameter
  36. // "result" which contains information about the test execution, such as whether the test
  37. // passed or failed, and any messages or exceptions thrown during the test. Developers can
  38. // add custom logic in this method, such as logging or teardown code for the test.
  39. }
  40. internal static void LogMetadata()
  41. {
  42. if (Saved) return;
  43. var run = Metadata.GetFromResources();
  44. var json = JsonUtility.ToJson(run);
  45. TestContext.Out?.WriteLine("##performancetestruninfo2:" + json);
  46. Saved = true;
  47. }
  48. }
  49. }