A game about forced loneliness, made by TACStudios
1using System; 2using UnityEngine.Scripting; 3 4namespace UnityEngine.TestRunner 5{ 6 /// <summary> 7 /// An assembly level attribute that indicates that a given type implementing <see cref = "ITestRunCallback"/> should be subscribed to updates on the test progress. You can invoke the callbacks with [NUnit](http://www.nunit.org/) `ITest` and `ITestResult` classes. 8 /// 9 /// At the `RunStarted` and `RunFinished` methods, the test and test results are for the whole test tree. These methods invoke at each node in the test tree; first with the whole test assembly, then with the test class, and last with the test method. 10 /// 11 /// From these callbacks, it's possible to read the partial or the full results, and to save the XML version of the result for further processing or continuous integration. 12 /// </summary> 13 /// <example> 14 /// <code> 15 /// <![CDATA[ 16 /// using NUnit.Framework.Interfaces; 17 /// using UnityEngine; 18 /// using UnityEngine.TestRunner; 19 /// 20 /// [assembly:TestRunCallback(typeof(TestListener))] 21 /// 22 /// public class TestListener : ITestRunCallback 23 /// { 24 /// public void RunStarted(ITest testsToRun) 25 /// { 26 /// 27 /// } 28 /// 29 /// public void RunFinished(ITestResult testResults) 30 /// { 31 /// Debug.Log($"Run finished with result {testResults.ResultState}."); 32 /// } 33 /// 34 /// public void TestStarted(ITest test) 35 /// { 36 /// 37 /// } 38 /// 39 /// public void TestFinished(ITestResult result) 40 /// { 41 /// 42 /// } 43 ///} 44 /// ]]> 45 /// </code> 46 /// > Note: The `TestRunCallback` does not need any references to the `UnityEditor` namespace and can run in standalone Players on the Player side. 47 /// </example> 48 [AttributeUsage(AttributeTargets.Assembly)] 49 public class TestRunCallbackAttribute : Attribute 50 { 51 private Type m_Type; 52 53 /// <summary> 54 /// Constructs a new instance of the <see cref="TestRunCallbackAttribute"/> class. 55 /// </summary> 56 /// <param name="type">A target type that implements <see cref="ITestRunCallback"/>.</param> 57 /// <exception cref="ArgumentException">Throws an ArgumentException if the provided type does not implement <see cref="ITestRunCallback"/>.</exception> 58 public TestRunCallbackAttribute(Type type) 59 { 60 var interfaceType = typeof(ITestRunCallback); 61 if (!interfaceType.IsAssignableFrom(type)) 62 { 63 throw new ArgumentException(string.Format( 64 "Type {2} provided to {0} does not implement {1}. If the stripping level is set to high, the implementing class should have the {3}.", 65 GetType().Name, interfaceType.Name, type.Name, typeof(PreserveAttribute).Name)); 66 } 67 m_Type = type; 68 } 69 70 internal ITestRunCallback ConstructCallback() 71 { 72 return Activator.CreateInstance(m_Type) as ITestRunCallback; 73 } 74 } 75}