// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution; using DebuggerLaunchMode = Microsoft.VisualStudio.TestTools.UnitTesting.DebuggerLaunchMode; using ExecutionScope = Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope; namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter; /// /// Adapter Settings for the run. /// #if NETFRAMEWORK [Serializable] #endif internal sealed partial class MSTestSettings { /// /// The settings name. /// public const string SettingsName = "MSTest"; /// /// The alias to the default settings name. /// public const string SettingsNameAlias = "MSTestV2"; private const string ParallelizeSettingsName = "Parallelize"; /// /// Initializes a new instance of the class. /// public MSTestSettings() { OutputCaptureMode = TestOutputCaptureMode.Result; MapInconclusiveToFailed = false; MapNotRunnableToFailed = true; TreatDiscoveryWarningsAsErrors = true; DisableParallelization = false; ConsiderEmptyDataSourceAsInconclusive = false; TestTimeout = 0; AssemblyInitializeTimeout = 0; ClassInitializeTimeout = 0; AssemblyCleanupTimeout = 0; ClassCleanupTimeout = 0; TestInitializeTimeout = 0; TestCleanupTimeout = 0; GlobalTestInitializeTimeout = 0; GlobalTestCleanupTimeout = 0; CooperativeCancellationTimeout = false; OrderTestsByNameInClass = false; RandomizeTestOrder = false; RandomTestOrderSeed = null; LaunchDebuggerOnAssertionFailure = DebuggerLaunchMode.Disabled; CaptureAssertionFailureDiagnostics = false; } /// /// Gets the current settings. /// [field: AllowNull] [field: MaybeNull] [AllowNull] public static MSTestSettings CurrentSettings { get => field ??= new MSTestSettings(); private set; } /// /// Gets the current configuration settings. /// [field: AllowNull] [field: MaybeNull] [AllowNull] public static RunConfigurationSettings RunConfigurationSettings { get => field ??= new RunConfigurationSettings(); private set; } /// /// Gets a value indicating whether capture debug traces. /// public bool CaptureDebugTraces => OutputCaptureMode != TestOutputCaptureMode.None; /// /// Gets a value indicating how Console/Trace output produced during test execution is handled. /// internal TestOutputCaptureMode OutputCaptureMode { get; private set; } /// /// Gets a value indicating whether an inconclusive result be mapped to failed test. /// public bool MapInconclusiveToFailed { get; private set; } /// /// Gets a value indicating whether a not runnable result be mapped to failed test. /// public bool MapNotRunnableToFailed { get; private set; } /// /// Gets a value indicating whether or not test discovery warnings should be treated as errors. /// public bool TreatDiscoveryWarningsAsErrors { get; private set; } /// /// Gets the number of threads/workers to be used for parallelization. /// public int? ParallelizationWorkers { get; private set; } /// /// Gets the scope of parallelization. /// public ExecutionScope? ParallelizationScope { get; private set; } /// /// Gets a value indicating whether the assembly can be parallelized. /// /// /// This is also re-used to disable parallelization on format errors. /// public bool DisableParallelization { get; private set; } /// /// Gets specified global test case timeout. /// public int TestTimeout { get; private set; } /// /// Gets specified global AssemblyInitialize timeout. /// internal int AssemblyInitializeTimeout { get; private set; } /// /// Gets specified global AssemblyCleanup timeout. /// internal int AssemblyCleanupTimeout { get; private set; } /// /// Gets a value indicating whether to enable marking tests with missing dynamic data as Inconclusive. /// internal bool ConsiderEmptyDataSourceAsInconclusive { get; private set; } /// /// Gets specified global ClassInitializeTimeout timeout. /// internal int ClassInitializeTimeout { get; private set; } /// /// Gets specified global ClassCleanupTimeout timeout. /// internal int ClassCleanupTimeout { get; private set; } /// /// Gets specified TestInitialize timeout. /// internal int TestInitializeTimeout { get; private set; } /// /// Gets specified TestCleanup timeout. /// internal int TestCleanupTimeout { get; private set; } /// /// Gets specified GlobalTestInitialize timeout. Falls back to when not set. /// internal int GlobalTestInitializeTimeout { get; private set; } /// /// Gets specified GlobalTestCleanup timeout. Falls back to when not set. /// internal int GlobalTestCleanupTimeout { get; private set; } /// /// Gets a value indicating whether all timeouts should be cooperative. /// internal bool CooperativeCancellationTimeout { get; private set; } /// /// Gets a value indicating whether tests should be ordered by name in the class. /// internal bool OrderTestsByNameInClass { get; private set; } /// /// Gets the test dependencies declared in testconfig.json under /// mstest:execution:dependencies, as an alternative to the [DependsOn] attribute, or /// when none are declared. Configured edges are merged with attribute-declared /// ones. /// /// /// This is only populated on the Microsoft.Testing.Platform path: testconfig.json is not supplied /// to the VSTest entry points, which pass a null configuration. Tests running under VSTest declare /// dependencies with the attribute. /// internal TestDependencyDeclaration[]? DeclaredDependencies { get; private set; } /// /// Gets a value indicating whether tests should be executed in a random order to help expose hidden dependencies between tests. /// /// /// When enabled, the adapter shuffles assemblies, parallel chunks and individual tests using /// (or an auto-generated seed). Tests marked with [DoNotParallelize] are still executed after the parallelizable set, /// but their relative order is also randomized. When this option is enabled, is ignored. /// internal bool RandomizeTestOrder { get; private set; } /// /// Gets the seed used to randomize test execution order when is enabled. /// /// /// When , the adapter generates a seed at run time and reports it in the run output so that the same /// order can be reproduced by setting this value to the reported seed. /// internal int? RandomTestOrderSeed { get; private set; } /// /// Gets a value specifying when to launch the debugger on assertion failure. /// internal DebuggerLaunchMode LaunchDebuggerOnAssertionFailure { get; private set; } /// /// Gets a value indicating whether a diagnostic artifact should be captured when an assertion fails. /// internal bool CaptureAssertionFailureDiagnostics { get; private set; } /// /// Resets any settings loaded. /// internal static void Reset() { CurrentSettings = null; RunConfigurationSettings = null; } }