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 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Linq;
  3. using NUnit.Framework.Interfaces;
  4. using NUnit.Framework.Internal.Filters;
  5. using UnityEngine;
  6. namespace UnityEditor.TestTools.TestRunner.Api
  7. {
  8. /// <summary>
  9. /// A set of execution settings defining how to run tests, using the <see cref="TestRunnerApi"/>.
  10. /// </summary>
  11. [Serializable]
  12. public class ExecutionSettings
  13. {
  14. /// <summary>
  15. /// Creates an instance with a given set of filters, if any.
  16. /// </summary>
  17. /// <param name="filtersToExecute">Set of filters</param>
  18. public ExecutionSettings(params Filter[] filtersToExecute)
  19. {
  20. filters = filtersToExecute;
  21. }
  22. [SerializeField]
  23. private BuildTarget m_TargetPlatform;
  24. [SerializeField]
  25. private bool m_HasTargetPlatform;
  26. /// <summary>
  27. /// An instance of <see cref="ITestRunSettings"/> to set up before running tests on a Player.
  28. /// </summary>
  29. // Note: Is not available after serialization
  30. public ITestRunSettings overloadTestRunSettings;
  31. [SerializeField]
  32. internal Filter filter;
  33. ///<summary>
  34. ///A collection of <see cref="Filter"/> to execute tests on.
  35. ///</summary>
  36. [SerializeField]
  37. public Filter[] filters;
  38. /// <summary>
  39. /// 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.
  40. /// </summary>
  41. /// <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>
  42. [SerializeField]
  43. public bool runSynchronously;
  44. /// <summary>
  45. /// The time, in seconds, the editor should wait for heartbeats after starting a test run on a player. This defaults to 10 minutes.
  46. /// </summary>
  47. [SerializeField]
  48. public int playerHeartbeatTimeout = 60 * 10;
  49. [SerializeField]
  50. internal string[] orderedTestNames;
  51. internal string playerSavePath { get; set; }
  52. internal bool EditModeIncluded()
  53. {
  54. return filters.Any(f => IncludesTestMode(f.testMode, TestMode.EditMode));
  55. }
  56. internal bool PlayModeInEditorIncluded()
  57. {
  58. return filters.Any(f => IncludesTestMode(f.testMode, TestMode.PlayMode) && targetPlatform == null);
  59. }
  60. internal bool PlayerIncluded()
  61. {
  62. return filters.Any(f => IncludesTestMode(f.testMode, TestMode.PlayMode) && targetPlatform != null);
  63. }
  64. private static bool IncludesTestMode(TestMode testMode, TestMode modeToCheckFor)
  65. {
  66. return (testMode & modeToCheckFor) == modeToCheckFor;
  67. }
  68. internal ITestFilter BuildNUnitFilter()
  69. {
  70. return new OrFilter(filters.Select(f => f.ToRuntimeTestRunnerFilter(runSynchronously).BuildNUnitFilter()).ToArray());
  71. }
  72. /// <returns>
  73. /// The <see cref="BuildTarget"/> platform to run the test on. If set to null, then the Editor is the target for the tests.
  74. /// </returns>
  75. internal BuildTarget? targetPlatform
  76. {
  77. get { return m_HasTargetPlatform ? (BuildTarget?)m_TargetPlatform : null; }
  78. set
  79. {
  80. {
  81. if (value.HasValue)
  82. {
  83. m_HasTargetPlatform = true;
  84. m_TargetPlatform = value.Value;
  85. }
  86. else
  87. {
  88. m_HasTargetPlatform = false;
  89. m_TargetPlatform = default;
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }