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

UnityTestExecutionContext.cs 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using NUnit.Framework;
  6. using NUnit.Framework.Constraints;
  7. using NUnit.Framework.Interfaces;
  8. using NUnit.Framework.Internal;
  9. using NUnit.Framework.Internal.Execution;
  10. using UnityEngine.TestTools;
  11. namespace UnityEngine.TestRunner.NUnitExtensions.Runner
  12. {
  13. internal class UnityTestExecutionContext : ITestExecutionContext
  14. {
  15. private readonly UnityTestExecutionContext _priorContext;
  16. private TestResult _currentResult;
  17. private int _assertCount;
  18. public static UnityTestExecutionContext CurrentContext { get; set; }
  19. public UnityTestExecutionContext Context { get; private set; }
  20. public bool Automated { get; set; }
  21. public Test CurrentTest { get; set; }
  22. public DateTime StartTime { get; set; }
  23. public long StartTicks { get; set; }
  24. public TestResult CurrentResult
  25. {
  26. get { return _currentResult; }
  27. set
  28. {
  29. _currentResult = value;
  30. if (value != null)
  31. OutWriter = value.OutWriter;
  32. }
  33. }
  34. public object TestObject { get; set; }
  35. public string WorkDirectory { get; set; }
  36. private TestExecutionStatus _executionStatus;
  37. public TestExecutionStatus ExecutionStatus
  38. {
  39. get
  40. {
  41. // ExecutionStatus may have been set to StopRequested or AbortRequested
  42. // in a prior context. If so, reflect the same setting in this context.
  43. if (_executionStatus == TestExecutionStatus.Running && _priorContext != null)
  44. _executionStatus = _priorContext.ExecutionStatus;
  45. return _executionStatus;
  46. }
  47. set
  48. {
  49. _executionStatus = value;
  50. // Push the same setting up to all prior contexts
  51. if (_priorContext != null)
  52. _priorContext.ExecutionStatus = value;
  53. }
  54. }
  55. public List<ITestAction> UpstreamActions { get; private set; }
  56. public int TestCaseTimeout { get; set; }
  57. public CultureInfo CurrentCulture { get; set; }
  58. public CultureInfo CurrentUICulture { get; set; }
  59. public ITestListener Listener { get; set; }
  60. public UnityTestExecutionContext()
  61. {
  62. UpstreamActions = new List<ITestAction>();
  63. SetUpTearDownState = new BeforeAfterTestCommandState();
  64. OuterUnityTestActionState = new BeforeAfterTestCommandState();
  65. EnumerableTestState = new EnumerableTestState();
  66. }
  67. public UnityTestExecutionContext(BeforeAfterTestCommandState setUpTearDownState,
  68. BeforeAfterTestCommandState outerUnityTestActionState, EnumerableTestState enumerableTestState) : this()
  69. {
  70. SetUpTearDownState = setUpTearDownState;
  71. OuterUnityTestActionState = outerUnityTestActionState;
  72. EnumerableTestState = enumerableTestState;
  73. }
  74. public UnityTestExecutionContext(UnityTestExecutionContext other)
  75. {
  76. _priorContext = other;
  77. CurrentTest = other.CurrentTest;
  78. CurrentResult = other.CurrentResult;
  79. TestObject = other.TestObject;
  80. WorkDirectory = other.WorkDirectory;
  81. Listener = other.Listener;
  82. TestCaseTimeout = other.TestCaseTimeout;
  83. UpstreamActions = new List<ITestAction>(other.UpstreamActions);
  84. SetUpTearDownState = other.SetUpTearDownState;
  85. OuterUnityTestActionState = other.OuterUnityTestActionState;
  86. EnumerableTestState = other.EnumerableTestState;
  87. TestContext.CurrentTestExecutionContext = this;
  88. CurrentCulture = other.CurrentCulture;
  89. CurrentUICulture = other.CurrentUICulture;
  90. TestMode = other.TestMode;
  91. IgnoreTests = other.IgnoreTests;
  92. FeatureFlags = other.FeatureFlags;
  93. CurrentContext = this;
  94. Automated = other.Automated;
  95. RepeatCount = other.RepeatCount;
  96. RetryCount = other.RetryCount;
  97. }
  98. public TextWriter OutWriter { get; private set; }
  99. public bool StopOnError { get; set; }
  100. public IWorkItemDispatcher Dispatcher { get; set; }
  101. public ParallelScope ParallelScope { get; set; }
  102. public string WorkerId { get; private set; }
  103. public Randomizer RandomGenerator { get; private set; }
  104. public ValueFormatter CurrentValueFormatter { get; private set; }
  105. public bool IsSingleThreaded { get; set; }
  106. public BeforeAfterTestCommandState SetUpTearDownState { get; set; }
  107. public BeforeAfterTestCommandState OuterUnityTestActionState { get; set; }
  108. public EnumerableTestState EnumerableTestState { get; set; }
  109. public IgnoreTest[] IgnoreTests { get; set; }
  110. public FeatureFlags FeatureFlags { get; set; }
  111. public int RetryCount { get; set; }
  112. public int RepeatCount { get; set; }
  113. public EnumerableTestState RetryRepeatState { get; set; }
  114. internal int AssertCount
  115. {
  116. get
  117. {
  118. return _assertCount;
  119. }
  120. }
  121. public TestPlatform TestMode { get; set; }
  122. public void IncrementAssertCount()
  123. {
  124. _assertCount += 1;
  125. }
  126. public void AddFormatter(ValueFormatterFactory formatterFactory)
  127. {
  128. throw new NotImplementedException();
  129. }
  130. }
  131. }