using System;
using System.Collections;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using Unity.PerformanceTesting.Data;
using Unity.PerformanceTesting.Runtime;
using UnityEngine.TestTools;
namespace Unity.PerformanceTesting
{
///
/// Test attribute to specify a performance test. It will add category "Performance" to test properties.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class PerformanceAttribute : CategoryAttribute, IOuterUnityTestAction
{
///
/// Adds performance attribute to a test method.
///
public PerformanceAttribute()
: base("Performance") { }
///
/// Executed before a test execution.
///
/// Test to execute.
///
public IEnumerator BeforeTest(ITest test)
{
if (RunSettings.Instance == null)
{
RunSettings.Instance = ResourcesLoader.Load(Utils.RunSettings, Utils.PlayerPrefKeySettingsJSON);
}
// domain reload will cause this method to be hit multiple times
// active performance test is serialized and survives reloads
if (PerformanceTest.Active == null)
{
PerformanceTest.StartTest(test);
yield return null;
}
}
///
/// Executed after a test execution.
///
/// Executed test.
///
public IEnumerator AfterTest(ITest test)
{
PerformanceTest.EndTest(test);
yield return null;
}
}
}