TestActionCommand.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using NUnit.Framework;
  5. using NUnit.Framework.Internal;
  6. using NUnit.Framework.Internal.Commands;
  7. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  8. namespace UnityEngine.TestTools
  9. {
  10. internal class TestActionCommand : BeforeAfterTestCommandBase<ITestAction>
  11. {
  12. static readonly Dictionary<MethodInfo, List<ITestAction>> m_TestActionsCache = new Dictionary<MethodInfo, List<ITestAction>>();
  13. public TestActionCommand(TestCommand innerCommand)
  14. : base(innerCommand, "BeforeTest", "AfterTest", true)
  15. {
  16. if (Test.TypeInfo.Type != null)
  17. {
  18. BeforeActions = GetTestActions(m_TestActionsCache, Test.Method.MethodInfo);
  19. AfterActions = BeforeActions;
  20. }
  21. }
  22. protected override IEnumerator InvokeBefore(ITestAction action, Test test, UnityTestExecutionContext context)
  23. {
  24. action.BeforeTest(test);
  25. yield return null;
  26. }
  27. protected override IEnumerator InvokeAfter(ITestAction action, Test test, UnityTestExecutionContext context)
  28. {
  29. action.AfterTest(test);
  30. yield return null;
  31. }
  32. protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
  33. {
  34. return null;
  35. }
  36. }
  37. }