No Description
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.

ExecutionSettings.cs 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using NUnit.Framework.Interfaces;
  5. using NUnit.Framework.Internal.Filters;
  6. using UnityEngine;
  7. using UnityEngine.Serialization;
  8. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  9. namespace UnityEditor.TestTools.TestRunner.Api
  10. {
  11. /// <summary>
  12. /// A set of execution settings defining how to run tests, using the <see cref="TestRunnerApi"/>.
  13. /// </summary>
  14. [Serializable]
  15. public class ExecutionSettings
  16. {
  17. /// <summary>
  18. /// Creates an instance with a given set of filters, if any.
  19. /// </summary>
  20. /// <param name="filtersToExecute">Set of filters</param>
  21. public ExecutionSettings(params Filter[] filtersToExecute)
  22. {
  23. filters = filtersToExecute;
  24. }
  25. [SerializeField]
  26. private BuildTarget m_TargetPlatform;
  27. [SerializeField]
  28. private bool m_HasTargetPlatform;
  29. /// <summary>
  30. /// An instance of <see cref="ITestRunSettings"/> to set up before running tests on a Player.
  31. /// </summary>
  32. // Note: Is not available after serialization
  33. public ITestRunSettings overloadTestRunSettings;
  34. [SerializeField]
  35. internal Filter filter;
  36. ///<summary>
  37. ///A collection of <see cref="Filter"/> to execute tests on.
  38. ///</summary>
  39. [SerializeField]
  40. public Filter[] filters;
  41. /// <summary>
  42. /// Note that this is only supported for EditMode tests, and that tests which take multiple frames (i.e. [UnityTest] tests, or tests with [UnitySetUp] or [UnityTearDown] scaffolding) will be filtered out.
  43. /// </summary>
  44. /// <returns>If true, the call to Execute() will run tests synchronously, guaranteeing that all tests have finished running by the time the call returns.</returns>
  45. [SerializeField]
  46. public bool runSynchronously;
  47. /// <summary>
  48. /// The time, in seconds, the editor should wait for heartbeats after starting a test run on a player. This defaults to 10 minutes.
  49. /// </summary>
  50. [SerializeField]
  51. public int playerHeartbeatTimeout = 60 * 10;
  52. [SerializeField]
  53. internal string[] orderedTestNames;
  54. [SerializeField]
  55. internal IgnoreTest[] ignoreTests;
  56. [SerializeField]
  57. internal FeatureFlags featureFlags;
  58. [SerializeField]
  59. internal int randomOrderSeed;
  60. internal string playerSavePath { get; set; }
  61. internal int retryCount { get; set; }
  62. internal int repeatCount { get; set; }
  63. internal bool EditModeIncluded()
  64. {
  65. return filters.Any(f => IncludesTestMode(f.testMode, TestMode.EditMode));
  66. }
  67. internal bool PlayModeInEditorIncluded()
  68. {
  69. return filters.Any(f => IncludesTestMode(f.testMode, TestMode.PlayMode) && targetPlatform == null);
  70. }
  71. internal bool PlayerIncluded()
  72. {
  73. return filters.Any(f => IncludesTestMode(f.testMode, TestMode.PlayMode) && targetPlatform != null);
  74. }
  75. private static bool IncludesTestMode(TestMode testMode, TestMode modeToCheckFor)
  76. {
  77. return (testMode & modeToCheckFor) == modeToCheckFor;
  78. }
  79. internal ITestFilter BuildNUnitFilter()
  80. {
  81. return new OrFilter(filters.Select(f => f.ToRuntimeTestRunnerFilter(runSynchronously).BuildNUnitFilter()).ToArray());
  82. }
  83. /// <summary>
  84. /// The <see cref="BuildTarget"/> platform to run the test on. If set to null, then the Editor is the target for the tests.
  85. /// </summary>
  86. internal BuildTarget? targetPlatform
  87. {
  88. get { return m_HasTargetPlatform ? (BuildTarget?)m_TargetPlatform : null; }
  89. set
  90. {
  91. {
  92. if (value.HasValue)
  93. {
  94. m_HasTargetPlatform = true;
  95. m_TargetPlatform = value.Value;
  96. }
  97. else
  98. {
  99. m_HasTargetPlatform = false;
  100. m_TargetPlatform = default;
  101. }
  102. }
  103. }
  104. }
  105. /// <summary>
  106. /// Implementation of ToString() that builds a string composed of the execution settings.
  107. /// </summary>
  108. /// <returns>The current execution settings as a string.</returns>
  109. public override string ToString()
  110. {
  111. var stringBuilder = new StringBuilder();
  112. stringBuilder.AppendLine($"{nameof(ExecutionSettings)} with details:");
  113. stringBuilder.AppendLine($"{nameof(targetPlatform)} = {targetPlatform}");
  114. stringBuilder.AppendLine($"{nameof(playerHeartbeatTimeout)} = {playerHeartbeatTimeout}");
  115. if (filters.Length == 0)
  116. {
  117. stringBuilder.AppendLine($"{nameof(filters)} = {{}}");
  118. }
  119. for (int i = 0; i < filters.Length; i++)
  120. {
  121. stringBuilder.AppendLine($"{nameof(filters)}[{i}] = ");
  122. var filterStrings = filters[i]
  123. .ToString()
  124. .Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
  125. .ToArray();
  126. foreach (var filterString in filterStrings)
  127. {
  128. stringBuilder.AppendLine($" {filterString}");
  129. }
  130. }
  131. if (ignoreTests == null || ignoreTests.Length == 0)
  132. {
  133. stringBuilder.AppendLine($"{nameof(ignoreTests)} = {{}}");
  134. }
  135. else
  136. {
  137. for (int i = 0; i < ignoreTests.Length; i++)
  138. {
  139. stringBuilder.AppendLine($"{nameof(ignoreTests)}[{i}] = {ignoreTests[i]}");
  140. }
  141. }
  142. if (featureFlags == null)
  143. {
  144. stringBuilder.AppendLine($"{nameof(featureFlags)} = null");
  145. }
  146. else
  147. {
  148. stringBuilder.AppendLine("Feature Flags:");
  149. stringBuilder.AppendLine($" {nameof(featureFlags.fileCleanUpCheck)} = {featureFlags.fileCleanUpCheck}");
  150. stringBuilder.AppendLine($" {nameof(featureFlags.requiresSplashScreen)} = {featureFlags.requiresSplashScreen}");
  151. stringBuilder.AppendLine($" {nameof(featureFlags.strictDomainReload)} = {featureFlags.strictDomainReload}");
  152. stringBuilder.AppendLine($" {nameof(featureFlags.disableNestedEnumeratorBugfix)} = {featureFlags.disableNestedEnumeratorBugfix}");
  153. }
  154. stringBuilder.AppendLine();
  155. return stringBuilder.ToString();
  156. }
  157. }
  158. }