SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
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.

49 lines
1.7 KiB

4 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using NUnit.Framework.Internal;
  5. using NUnit.Framework.Internal.Commands;
  6. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  7. namespace UnityEngine.TestTools
  8. {
  9. internal class OuterUnityTestActionCommand : BeforeAfterTestCommandBase<IOuterUnityTestAction>
  10. {
  11. public OuterUnityTestActionCommand(TestCommand innerCommand)
  12. : base(innerCommand, "BeforeTest", "AfterTest")
  13. {
  14. if (Test.TypeInfo.Type != null)
  15. {
  16. BeforeActions = GetUnityTestActionsFromMethod(Test.Method.MethodInfo);
  17. AfterActions = BeforeActions;
  18. }
  19. }
  20. private static IOuterUnityTestAction[] GetUnityTestActionsFromMethod(MethodInfo method)
  21. {
  22. var attributes = method.GetCustomAttributes(false);
  23. List<IOuterUnityTestAction> actions = new List<IOuterUnityTestAction>();
  24. foreach (var attribute in attributes)
  25. {
  26. if (attribute is IOuterUnityTestAction)
  27. actions.Add(attribute as IOuterUnityTestAction);
  28. }
  29. return actions.ToArray();
  30. }
  31. protected override IEnumerator InvokeBefore(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context)
  32. {
  33. return action.BeforeTest(test);
  34. }
  35. protected override IEnumerator InvokeAfter(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context)
  36. {
  37. return action.AfterTest(test);
  38. }
  39. protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
  40. {
  41. return context.OuterUnityTestActionState;
  42. }
  43. }
  44. }