// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// /// Provides ambient access to information about the currently-executing test run. /// /// /// /// always returns a non- ; /// before tests start executing it exposes empty collections. /// /// /// The information is scoped to the current process and (on .NET Framework) the current /// AppDomain. Cross-process or cross-AppDomain test runs each have their own snapshot. /// /// /// This API is experimental. It may change, break, or be removed at any time without notice. /// /// [Experimental("MSTESTEXP", UrlFormat = "https://aka.ms/mstest/diagnostics#{0}")] public static class TestRun { /// /// Gets information about the currently-executing test run. Never returns . /// public static ITestRunInfo Current { get; private set; } = EmptyTestRunInfo.Instance; /// /// Set by the platform before executing tests for an assembly. Pass to /// reset to the empty implementation. /// internal static void SetCurrent(ITestRunInfo? info) => Current = info ?? EmptyTestRunInfo.Instance; private sealed class EmptyTestRunInfo : ITestRunInfo { public static EmptyTestRunInfo Instance { get; } = new(); public IReadOnlyCollection PlannedTests { get; } = []; } }