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