暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TestRunCallbackAttribute.cs 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using UnityEngine.Scripting;
  3. namespace UnityEngine.TestRunner
  4. {
  5. /// <summary>
  6. /// An assembly level attribute that indicates that a given type should be subscribed for receiving updates on the test progress.
  7. /// </summary>
  8. /// <example>
  9. /// <code>
  10. /// using NUnit.Framework.Interfaces;
  11. /// using UnityEngine;
  12. /// using UnityEngine.TestRunner;
  13. ///
  14. /// [assembly:TestRunCallback(typeof(TestListener))]
  15. ///
  16. /// public class TestListener : ITestRunCallback
  17. /// {
  18. /// public void RunStarted(ITest testsToRun)
  19. /// {
  20. ///
  21. /// }
  22. ///
  23. /// public void RunFinished(ITestResult testResults)
  24. /// {
  25. /// Debug.Log($"Run finished with result {testResults.ResultState}.");
  26. /// }
  27. ///
  28. /// public void TestStarted(ITest test)
  29. /// {
  30. ///
  31. /// }
  32. ///
  33. /// public void TestFinished(ITestResult result)
  34. /// {
  35. ///
  36. /// }
  37. ///}
  38. /// </code>
  39. /// </example>
  40. [AttributeUsage(AttributeTargets.Assembly)]
  41. public class TestRunCallbackAttribute : Attribute
  42. {
  43. private Type m_Type;
  44. /// <summary>
  45. /// Constructs a new instance of the <see cref="TestRunCallbackAttribute"/> class.
  46. /// </summary>
  47. /// <param name="type">A target type that implements <see cref="ITestRunCallback"/>.</param>
  48. /// <exception cref="ArgumentException">Throws an ArgumentException if the provided type does not implement <see cref="ITestRunCallback"/>.</exception>
  49. public TestRunCallbackAttribute(Type type)
  50. {
  51. var interfaceType = typeof(ITestRunCallback);
  52. if (!interfaceType.IsAssignableFrom(type))
  53. {
  54. throw new ArgumentException(string.Format(
  55. "Type {2} provided to {0} does not implement {1}. If the stripping level is set to high, the implementing class should have the {3}.",
  56. this.GetType().Name, interfaceType.Name, type.Name, typeof(PreserveAttribute).Name));
  57. }
  58. m_Type = type;
  59. }
  60. internal ITestRunCallback ConstructCallback()
  61. {
  62. return Activator.CreateInstance(m_Type) as ITestRunCallback;
  63. }
  64. }
  65. }