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

PerformanceAttribute.cs 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections;
  3. using NUnit.Framework;
  4. using NUnit.Framework.Interfaces;
  5. using Unity.PerformanceTesting.Data;
  6. using Unity.PerformanceTesting.Runtime;
  7. using UnityEngine.TestTools;
  8. namespace Unity.PerformanceTesting
  9. {
  10. /// <summary>
  11. /// Test attribute to specify a performance test. It will add category "Performance" to test properties.
  12. /// </summary>
  13. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
  14. public class PerformanceAttribute : CategoryAttribute, IOuterUnityTestAction
  15. {
  16. /// <summary>
  17. /// Adds performance attribute to a test method.
  18. /// </summary>
  19. public PerformanceAttribute()
  20. : base("Performance") { }
  21. /// <summary>
  22. /// Executed before a test execution.
  23. /// </summary>
  24. /// <param name="test">Test to execute.</param>
  25. /// <returns></returns>
  26. public IEnumerator BeforeTest(ITest test)
  27. {
  28. if (RunSettings.Instance == null)
  29. {
  30. RunSettings.Instance = ResourcesLoader.Load<RunSettings>(Utils.RunSettings, Utils.PlayerPrefKeySettingsJSON);
  31. }
  32. // domain reload will cause this method to be hit multiple times
  33. // active performance test is serialized and survives reloads
  34. if (PerformanceTest.Active == null)
  35. {
  36. PerformanceTest.StartTest(test);
  37. yield return null;
  38. }
  39. }
  40. /// <summary>
  41. /// Executed after a test execution.
  42. /// </summary>
  43. /// <param name="test">Executed test.</param>
  44. /// <returns></returns>
  45. public IEnumerator AfterTest(ITest test)
  46. {
  47. PerformanceTest.EndTest(test);
  48. yield return null;
  49. }
  50. }
  51. }