暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ExecutionSettings.cs 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. internal BuildTarget? targetPlatform;
  24. /// <summary>
  25. /// An instance of <see cref="ITestRunSettings"/> to set up before running tests on a Player.
  26. /// </summary>
  27. // Note: Is not available after serialization
  28. public ITestRunSettings overloadTestRunSettings;
  29. [SerializeField]
  30. internal Filter filter;
  31. ///<summary>
  32. ///A collection of <see cref="Filter"/> to execute tests on.
  33. ///</summary>
  34. [SerializeField]
  35. public Filter[] filters;
  36. /// <summary>
  37. /// 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.
  38. /// </summary>
  39. /// <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>
  40. [SerializeField]
  41. public bool runSynchronously;
  42. /// <summary>
  43. /// The time, in seconds, the editor should wait for heartbeats after starting a test run on a player. This defaults to 10 minutes.
  44. /// </summary>
  45. [SerializeField]
  46. public int playerHeartbeatTimeout = 60*10;
  47. internal string playerSavePath { get; set; }
  48. internal bool EditModeIncluded()
  49. {
  50. return filters.Any(f => IncludesTestMode(f.testMode, TestMode.EditMode));
  51. }
  52. internal bool PlayModeInEditorIncluded()
  53. {
  54. return filters.Any(f => IncludesTestMode(f.testMode, TestMode.PlayMode) && targetPlatform == null);
  55. }
  56. internal bool PlayerIncluded()
  57. {
  58. return filters.Any(f => IncludesTestMode(f.testMode, TestMode.PlayMode) && targetPlatform != null);
  59. }
  60. private static bool IncludesTestMode(TestMode testMode, TestMode modeToCheckFor)
  61. {
  62. return (testMode & modeToCheckFor) == modeToCheckFor;
  63. }
  64. internal ITestFilter BuildNUnitFilter()
  65. {
  66. return new OrFilter(filters.Select(f => f.ToRuntimeTestRunnerFilter(runSynchronously).BuildNUnitFilter()).ToArray());
  67. }
  68. }
  69. }