Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TestAdaptor.cs 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using NUnit.Framework.Interfaces;
  5. using NUnit.Framework.Internal;
  6. using UnityEngine;
  7. using UnityEngine.TestRunner.NUnitExtensions;
  8. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  9. using UnityEngine.TestRunner.TestLaunchers;
  10. using UnityEngine.TestTools;
  11. using UnityEngine.TestTools.Utils;
  12. namespace UnityEditor.TestTools.TestRunner.Api
  13. {
  14. internal class TestAdaptor : ITestAdaptor
  15. {
  16. internal TestAdaptor(ITest test, ITestAdaptor[] children = null)
  17. {
  18. Id = test.Id;
  19. Name = test.Name;
  20. var childIndex = -1;
  21. if (test.Properties["childIndex"].Count > 0)
  22. {
  23. childIndex = (int)test.Properties["childIndex"][0];
  24. }
  25. FullName = TestExtensions.GetFullName(test.FullName, childIndex);
  26. TestCaseCount = test.TestCaseCount;
  27. HasChildren = test.HasChildren;
  28. IsSuite = test.IsSuite;
  29. if (UnityTestExecutionContext.CurrentContext != null)
  30. {
  31. TestCaseTimeout = UnityTestExecutionContext.CurrentContext.TestCaseTimeout;
  32. }
  33. else
  34. {
  35. TestCaseTimeout = TimeoutCommand.k_DefaultTimeout;
  36. }
  37. TypeInfo = test.TypeInfo;
  38. Method = test.Method;
  39. Arguments = test is TestMethod testMethod ? testMethod.parms?.Arguments : (test as TestSuite)?.Arguments;
  40. Categories = test.GetAllCategoriesFromTest().Distinct().ToArray();
  41. IsTestAssembly = test is TestAssembly;
  42. RunState = (RunState)Enum.Parse(typeof(RunState), test.RunState.ToString());
  43. Description = (string)test.Properties.Get(PropertyNames.Description);
  44. SkipReason = test.GetSkipReason();
  45. ParentId = test.GetParentId();
  46. ParentFullName = test.GetParentFullName();
  47. UniqueName = test.GetUniqueName();
  48. ParentUniqueName = test.GetParentUniqueName();
  49. ChildIndex = childIndex;
  50. var testPlatform = test.Properties.Get("platform");
  51. if (testPlatform is TestPlatform platform)
  52. {
  53. TestMode = PlatformToTestMode(platform);
  54. }
  55. Children = children;
  56. }
  57. public void SetParent(ITestAdaptor parent)
  58. {
  59. Parent = parent;
  60. if (parent != null)
  61. {
  62. TestMode = parent.TestMode;
  63. }
  64. }
  65. internal TestAdaptor(RemoteTestData test)
  66. {
  67. Id = test.id;
  68. Name = test.name;
  69. FullName = TestExtensions.GetFullName(test.fullName, test.ChildIndex);
  70. TestCaseCount = test.testCaseCount;
  71. HasChildren = test.hasChildren;
  72. IsSuite = test.isSuite;
  73. m_ChildrenIds = test.childrenIds;
  74. TestCaseTimeout = test.testCaseTimeout;
  75. Categories = test.Categories;
  76. IsTestAssembly = test.IsTestAssembly;
  77. RunState = (RunState)Enum.Parse(typeof(RunState), test.RunState.ToString());
  78. Description = test.Description;
  79. SkipReason = test.SkipReason;
  80. ParentId = test.ParentId;
  81. UniqueName = test.UniqueName;
  82. ParentUniqueName = test.ParentUniqueName;
  83. ParentFullName = test.ParentFullName;
  84. ChildIndex = test.ChildIndex;
  85. TestMode = TestMode.PlayMode;
  86. }
  87. internal void ApplyChildren(IEnumerable<TestAdaptor> allTests)
  88. {
  89. Children = m_ChildrenIds.Select(id => allTests.First(t => t.Id == id)).ToArray();
  90. if (!string.IsNullOrEmpty(ParentId))
  91. {
  92. Parent = allTests.FirstOrDefault(t => t.Id == ParentId);
  93. }
  94. }
  95. private static TestMode PlatformToTestMode(TestPlatform testPlatform)
  96. {
  97. switch (testPlatform)
  98. {
  99. case TestPlatform.All:
  100. return TestMode.EditMode | TestMode.PlayMode;
  101. case TestPlatform.EditMode:
  102. return TestMode.EditMode;
  103. case TestPlatform.PlayMode:
  104. return TestMode.PlayMode;
  105. default:
  106. return default;
  107. }
  108. }
  109. public string Id { get; private set; }
  110. public string Name { get; private set; }
  111. public string FullName { get; private set; }
  112. public int TestCaseCount { get; private set; }
  113. public bool HasChildren { get; private set; }
  114. public bool IsSuite { get; private set; }
  115. public IEnumerable<ITestAdaptor> Children { get; private set; }
  116. public ITestAdaptor Parent { get; private set; }
  117. public int TestCaseTimeout { get; private set; }
  118. public ITypeInfo TypeInfo { get; private set; }
  119. public IMethodInfo Method { get; private set; }
  120. public object[] Arguments { get; }
  121. private string[] m_ChildrenIds;
  122. public string[] Categories { get; private set; }
  123. public bool IsTestAssembly { get; private set; }
  124. public RunState RunState { get; }
  125. public string Description { get; }
  126. public string SkipReason { get; }
  127. public string ParentId { get; }
  128. public string ParentFullName { get; }
  129. public string UniqueName { get; }
  130. public string ParentUniqueName { get; }
  131. public int ChildIndex { get; }
  132. public TestMode TestMode { get; private set; }
  133. }
  134. }