Skip to content

Use MSTest recommended analyzers (continuation of #15539)#15558

Closed
nohwnd wants to merge 6 commits into
microsoft:mainfrom
nohwnd:fix-mstest-analyzers
Closed

Use MSTest recommended analyzers (continuation of #15539)#15558
nohwnd wants to merge 6 commits into
microsoft:mainfrom
nohwnd:fix-mstest-analyzers

Conversation

@nohwnd
Copy link
Copy Markdown
Member

@nohwnd nohwnd commented Mar 24, 2026

This PR builds on @Evangelink's work in #15539 to apply MSTest recommended analyzers to test files.

Changes from #15539

  • All of Amaury's analyzer fixes (160 files) converting assertions to MSTest v4 APIs:
    • \\Assert.AreEqual(0, x.Count)\\ → \\Assert.IsEmpty(x)\\
    • \\Assert.IsTrue(x > 0)\\ → \\Assert.IsGreaterThan(x, 0)\\
    • \\Assert.AreEqual(1, x.Count)\\ → \\Assert.HasCount(1, x)\\
    • And other MSTest analyzer recommendations

Merge conflict resolution

Verification

  • Build succeeds with 0 errors
  • All new assertion APIs compile correctly with the MSTest version in the test projects

Evangelink and others added 4 commits March 20, 2026 15:21
…s' into fix-mstest-analyzers

Resolve merge conflicts by keeping upstream removal of deprecated WebTest
and TMI test methods (removed in microsoft#15525), while preserving all of Amaury's
MSTest analyzer fixes in the remaining files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 24, 2026 06:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Applies MSTest “Recommended” analyzer rules across the test suite and updates tests to use newer MSTest assertion APIs / patterns (including cancellation-token-aware waits), continuing the work from #15539.

Changes:

  • Replaced many legacy Assert.IsTrue(...) / StringAssert.* / custom ExceptionUtilities.ThrowsException usages with MSTest recommended asserts (e.g., ThrowsExactly, HasCount, Contains, regex asserts).
  • Introduced TestContext.CancellationToken usage in multiple multi-threaded / timing-sensitive tests and added targeted analyzer suppressions where needed (e.g., Moq callbacks, .NET Framework API gaps).
  • Enabled MSTest analyzer “Recommended” mode in test build props and removed the custom ExceptionUtilities helper.

Reviewed changes

Copilot reviewed 160 out of 160 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/vstest.console.UnitTests/Processors/Utilities/ArgumentProcessorUtilitiesTests.cs Switches exception/assert patterns to MSTest recommended APIs.
test/vstest.console.UnitTests/Processors/Utilities/ArgumentProcessorFactoryTests.cs Replaces custom throw helper usage with ThrowsExactly + message checks.
test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs Uses ThrowsExactly and MSTest string asserts.
test/vstest.console.UnitTests/Processors/TestCaseFilterArgumentProcessorTests.cs Updates string contains and exception assertions.
test/vstest.console.UnitTests/Processors/TestAdapterPathArgumentProcessorTests.cs Simplifies “exception thrown” patterns using ThrowsExactly.
test/vstest.console.UnitTests/Processors/TestAdapterLoadingStrategyArgumentProcessorTests.cs Simplifies “exception thrown” patterns using ThrowsExactly.
test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs Updates help text assertions to Assert.Contains.
test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs Replaces throw helper and strengthens message assertions; adds CultureInfo usage.
test/vstest.console.UnitTests/Processors/ResultsDirectoryArgumentProcessorTests.cs Simplifies exception/assert template via ThrowsExactly.
test/vstest.console.UnitTests/Processors/ResponseFileArgumentProcessorTests.cs Converts StringAssert.Contains to Assert.Contains.
test/vstest.console.UnitTests/Processors/PortArgumentProcessorTests.cs Converts try/catch assertions to ThrowsExactly.
test/vstest.console.UnitTests/Processors/PlatformArgumentProcessorTests.cs Converts throw helper to ThrowsExactly; uses formatted messages.
test/vstest.console.UnitTests/Processors/ParentProcessIdArgumentProcessorTests.cs Adjusts priority assertion and modernizes exception assertions.
test/vstest.console.UnitTests/Processors/ParallelArgumentProcessorTests.cs Converts throw helper to ThrowsExactly + message contains.
test/vstest.console.UnitTests/Processors/ListTestsTargetPathArgumentProcessorTests.cs Converts exception assertions to ThrowsExactly + message check.
test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs Converts count/contains assertions to MSTest v4 collection APIs.
test/vstest.console.UnitTests/Processors/InIsolationArgumentProcessorTests.cs Converts throw helper to ThrowsExactly + message contains.
test/vstest.console.UnitTests/Processors/HelpArgumentProcessorTests.cs Converts Contains checks to direct collection membership asserts.
test/vstest.console.UnitTests/Processors/FrameworkArgumentProcessorTests.cs Updates help text contains + exception assertions; adds CultureInfo.
test/vstest.console.UnitTests/Processors/EnvironmentArgumentProcessorTests.cs Converts array length asserts to HasCount.
test/vstest.console.UnitTests/Processors/EnableLoggersArgumentProcessorTests.cs Converts exception/assert patterns and string-contains checks.
test/vstest.console.UnitTests/Processors/EnableDiagArgumentProcessorTests.cs Removes “expect no exception” try/catch; updates contains assert.
test/vstest.console.UnitTests/Processors/EnableCodeCoverageArgumentProcessorTests.cs Uses Assert.Contains for collection membership.
test/vstest.console.UnitTests/Processors/CollectArgumentProcessorTests.cs Simplifies exception assertion using ThrowsExactly.
test/vstest.console.UnitTests/Processors/CLIRunSettingsArgumentProcessorTests.cs Reorders using; converts throw helper to ThrowsExactly.
test/vstest.console.UnitTests/Internal/FilePatternParserTests.cs Converts Contains checks to Assert.Contains.
test/vstest.console.UnitTests/InProcessVsTestConsoleWrapperTests.cs Replaces boolean asserts with AreEqual.
test/vstest.console.UnitTests/ExecutorUnitTests.cs Broadly replaces assertions with MSTest v4 APIs (counts/contains/regex).
test/vstest.console.UnitTests/ExceptionUtilities.cs Removes now-unneeded custom throw helper.
test/vstest.console.UnitTests/CommandLine/InferHelperTests.cs Converts count assertions to HasCount.
test/testhost.UnitTests/UnitTestClientTests.cs Converts array length asserts to HasCount.
test/testhost.UnitTests/AppDomainEngineInvokerTests.cs Updates string contains / not-contains patterns to new asserts.
test/datacollector.UnitTests/DataCollectionManagerTests.cs Converts empty/count/contains patterns to MSTest v4 APIs.
test/datacollector.UnitTests/DataCollectionAttachmentManagerTests.cs Adds TestContext cancellation token usage for parallel tests + modern assertions.
test/datacollector.PlatformTests/CommunicationLayerIntegrationTests.cs Updates string contains assertion.
test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs Adds TestContext + cancellation-token-aware delays and suppressions.
test/TranslationLayer.UnitTests/ConsoleParametersTests.cs Updates string prefix assertion to Assert.StartsWith.
test/SettingsMigrator.UnitTests/PathResolverTests.cs Converts string contains to Assert.Contains.
test/SettingsMigrator.UnitTests/MigratorTests.cs Converts node-count assert to HasCount.
test/Microsoft.TestPlatform.Utilities.UnitTests/StringUtilitiesTests.cs Replaces size/equality assertions with HasCount / AreEqual.
test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs Replaces many string search asserts with recommended numeric/string asserts.
test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageRunSettingsProcessorTests.cs Converts node-count + empty-set checks to HasCount / IsEmpty.
test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs Replaces count comparisons with HasCount / IsEmpty.
test/Microsoft.TestPlatform.TestUtilities/SourceAssert.cs Updates assertions to collection predicate-based Assert.Contains.
test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs Switches from StringAssert/manual Contains to new MSTest APIs.
test/Microsoft.TestPlatform.TestUtilities/FileAssert.cs Converts string contains to Assert.Contains.
test/Microsoft.TestPlatform.TestUtilities/CodeCoverageAcceptanceTestBase.cs Updates numeric and XML-node assertions to newer APIs.
test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs Adds TestContext cancellation token usage + modern string/path asserts.
test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestResultTests.cs Uses IsEmpty and time comparisons via IsLessThan.
test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestObjectTests.cs Converts list membership to Assert.Contains.
test/Microsoft.TestPlatform.ObjectModel.UnitTests/RunSettings/RunConfigurationTests.cs Converts StringAssert.Contains to Assert.Contains.
test/Microsoft.TestPlatform.ObjectModel.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs Converts string prefix/suffix/contains checks to new asserts.
test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomStringArrayConverterTests.cs Converts array length asserts to HasCount / IsEmpty.
test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomKeyValueConverterTests.cs Converts array length asserts to HasCount / IsEmpty.
test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/BaseTestRunCriteriaTests.cs Simplifies exception assertions via ThrowsExactly.
test/Microsoft.TestPlatform.Library.IntegrationTests/TranslationLayerTests/TargetFrameworkTestHostDemultiplexer.cs Updates count and comparison asserts to MSTest v4 APIs.
test/Microsoft.TestPlatform.Library.IntegrationTests/TranslationLayerTests/SerializeTestRunTests.cs Updates count + comparison asserts to MSTest v4 APIs.
test/Microsoft.TestPlatform.Library.IntegrationTests/TranslationLayerTests/RunTestsWithFilterTests.cs Removes BOM + uses ContainsSingle / HasCount patterns.
test/Microsoft.TestPlatform.Library.IntegrationTests/TranslationLayerTests/RunTestsWithDifferentConfigurationTests.cs Removes BOM + updates asserts for counts/singletons.
test/Microsoft.TestPlatform.Library.IntegrationTests/TranslationLayerTests/RunTests.cs Updates count assertions to HasCount and string prefix/suffix asserts.
test/Microsoft.TestPlatform.Library.IntegrationTests/TranslationLayerTests/RunSelectedTests.cs Updates count assertions to HasCount.
test/Microsoft.TestPlatform.Library.IntegrationTests/TranslationLayerTests/LiveUnitTestingTests.cs Updates count assertions to HasCount.
test/Microsoft.TestPlatform.Library.IntegrationTests/TranslationLayerTests/DiscoverTests.cs Updates count and ends-with asserts; uses cancellation-token-aware Task.Run.
test/Microsoft.TestPlatform.Library.IntegrationTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs Removes BOM + modernizes ends-with and count asserts.
test/Microsoft.TestPlatform.Library.IntegrationTests/MetadataReaderHelperTests.cs Updates prefix asserts to Assert.StartsWith.
test/Microsoft.TestPlatform.Library.IntegrationTests/DiaSessionTests.cs Updates ends-with and perf timing asserts.
test/Microsoft.TestPlatform.Library.IntegrationTests/DeprecateExtensionsPathWarningTests.cs Removes [TestClass] attribute line.
test/Microsoft.TestPlatform.Library.IntegrationTests/Build.cs Changes assembly init container type.
test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs Converts count/contains to MSTest v4 APIs.
test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs Adds TestContext cancellation token usage; modernizes asserts.
test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs Simplifies exception assertions and modernizes count/contains asserts.
test/Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests/XmlReaderWriterTests.cs Converts “length > 0” to IsGreaterThan.
test/Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests/InactivityTimerTests.cs Adds TestContext cancellation token usage for waits.
test/Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests/BlameCollectorTests.cs Adds TestContext cancellation token usage for barriers/waits.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Utilities/TestSourcesUtilityTests.cs Removes BOM + converts membership asserts to Assert.Contains.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestExtensionManagerTests.cs Converts count to IsEmpty.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestEngineTests.cs Converts membership asserts to Assert.Contains.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/TestRunCacheTests.cs Converts count/empty/single asserts to MSTest v4 APIs.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/ExecutionManagerTests.cs Converts “count > 0” to Assert.IsNotEmpty.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/BaseRunTestsTests.cs Converts count to IsEmpty.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/EventHandlers/TestRequestHandlerTests.cs Adds TestContext + cancellation-token-aware waits and suppressions.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Discovery/TestCaseDiscoverySinkTests.cs Uses Assert.ContainsSingle for singleton list.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Discovery/DiscoveryResultCacheTests.cs Adds TestContext and makes timeout waits cancellation-token-aware.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Discovery/DiscoveryManagerTests.cs Converts boolean equality to Assert.IsTrue.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Discovery/DiscovererEnumeratorTests.cs Converts count asserts to HasCount.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyOutOfProcDataCollectionManagerTests.cs Removes BOM + converts attachment asserts.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs Converts counts to HasCount / IsEmpty / ContainsSingle.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/InProcDataCollectionExtensionManagerTests.cs Removes BOM + modernizes count/membership assertions.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionTestRunEventsHandlerTests.cs Converts counts to ContainsSingle / HasCount.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyTestSessionManagerTests.cs Simplifies boolean equality to Assert.IsTrue.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs Updates equality asserts and adds targeted analyzer suppression.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs Converts string contains and empties to MSTest v4 APIs.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyDiscoveryManagerTests.cs Converts empty list asserts to IsEmpty.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyBaseManagerTests.cs Removes [TestClass] attribute line.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyExecutionManagerTests.cs Adds analyzer suppression + modernizes count/singleton asserts.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyDiscoveryManagerTests.cs Removes BOM, adds suppression, updates asserts.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelOperationManagerTests.cs Adds analyzer suppression comment for cancellation token.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/DiscoveryDataAggregatorTests.cs Removes BOM + modernizes count/singleton assertions.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/AttachmentsProcessing/TestRunAttachmentsProcessingManagerTests.cs Removes BOM + adds suppression + modernizes assertions.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/AttachmentsProcessing/DataCollectorAttachmentProcessorAppDomainTests.cs Removes BOM + modernizes count/contains asserts.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Adapter/TestExecutionRecorderTests.cs Modernizes empty/membership assertions.
test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Adapter/FrameworkHandleTests.cs Simplifies exception assertion with ThrowsExactly.
test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Utilities/JobQueueTests.cs Updates empties/counts and makes [Timeout] cooperative.
test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Tracing/EqtTraceTests.cs Replaces string Contains/!Contains with Assert.Contains / DoesNotContain.
test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Output/OutputExtensionsTests.cs Converts boolean comparisons to AreEqual.
test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Helpers/CommandLineArgumentsHelperTests.cs Converts dictionary size checks to HasCount/IsEmpty.
test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs Adds TestContext cancellation token for Task.Run.
test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/SocketCommunicationManagerTest.cs Converts to static/empty container type.
test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/Serialization/TestResultSerializationTests.cs Converts count checks to HasCount / IsEmpty.
test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/Serialization/TestObjectConverterTests.cs Converts array length asserts and boolean equality patterns.
test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/Serialization/TestCaseSerializationTests.cs Converts array length asserts to HasCount.
test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestSenderTests.cs Converts counts to HasCount / IsEmpty and tightens null checking.
test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs Converts collection membership check to Assert.Contains.
test/Microsoft.TestPlatform.CommunicationUtilities.Platform.UnitTests/SocketServerTests.cs Adds TestContext and uses cancellation token in wait.
test/Microsoft.TestPlatform.CommunicationUtilities.Platform.UnitTests/SocketCommunicationManagerTests.cs Adds TestContext, adds suppressions for .NET Framework API gaps, updates OS gating and assertions.
test/Microsoft.TestPlatform.CommunicationUtilities.Platform.UnitTests/SocketClientTests.cs Adds targeted suppressions for .NET Framework async APIs and updates waits.
test/Microsoft.TestPlatform.Common.UnitTests/Utilities/ExceptionUtilitiesTests.cs Converts StringAssert to Assert.Contains.
test/Microsoft.TestPlatform.Common.UnitTests/Telemetry/MetricsCollectionTests.cs Converts count checks to HasCount / IsEmpty.
test/Microsoft.TestPlatform.Common.UnitTests/SourceNavigationParserTests.cs Converts count checks to ContainsSingle / HasCount / IsEmpty.
test/Microsoft.TestPlatform.Common.UnitTests/SettingsProvider/SettingsProviderExtensionManagerTests.cs Converts “count > 0” to Assert.IsNotEmpty.
test/Microsoft.TestPlatform.Common.UnitTests/RunSettingsTests.cs Converts StringAssert.Contains to Assert.Contains.
test/Microsoft.TestPlatform.Common.UnitTests/Filtering/FilterExpressionTests.cs Removes BOM + converts array length asserts to HasCount.
test/Microsoft.TestPlatform.Common.UnitTests/Filtering/ConditionTests.cs Removes BOM + converts array length asserts to HasCount.
test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/Utilities/TestDiscovererPluginInformationTests.cs Converts empty/list-count asserts to IsEmpty.
test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/Utilities/RunSettingsProviderExtensionsTests.cs Converts StringAssert.Contains to Assert.Contains.
test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginDiscovererTests.cs Uses ContainsSingle and numeric comparisons for key counts.
test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginCacheTests.cs Converts many “count == 1/0” cases to ContainsSingle / IsEmpty / IsNotEmpty.
test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/ExtensionDecoratorTests.cs Adds suppression around Moq callback Task.Run setup.
test/Microsoft.TestPlatform.Client.UnitTests/Execution/TestRunRequestTests.cs Adds TestContext, simplifies exception assertions, updates launcher verification signature.
test/Microsoft.TestPlatform.Client.UnitTests/Discovery/DiscoveryRequestTests.cs Simplifies exception assertions and converts event count asserts.
test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeTestHostLauncherTests.cs Adds TestContext and passes cancellation token to launcher calls.
test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs Adds TestContext and makes async callbacks cancellation-token-aware.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/VideoRecorderTests.cs Replaces Length > 0 with Assert.IsNotEmpty.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/PostProcessingTests.cs Converts prefix check to Assert.StartsWith.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/ManagedNameTests/SpecialNameTests.cs Replaces reference equality check with AreEqual.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/LoggerTests.cs Converts numeric comparison + contains usage to new assertions.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/ExecutionTests.cs Converts StringAssert.Contains to Assert.Contains.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/EventLogCollectorTests.cs Converts count to HasCount.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DiscoveryTests.cs Converts StringAssert.Contains to Assert.Contains.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DebugAssertTests.cs Converts StringAssert.Contains to Assert.Contains.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DataCollectorTests.Coverlet.cs Converts file-content contains checks to Assert.Contains.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DataCollectorAttachmentsProcessorsFactoryTests.cs Converts counts and uniqueness checks to HasCount / ContainsSingle.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DataCollectionTests.cs Converts prefix/contains checks to Assert.StartsWith / Assert.Contains.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/CodeCoverageTests.cs Converts numeric comparison to Assert.IsGreaterThan.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Build.cs Changes assembly init container type.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/BlameDataCollectorTests.cs Converts string checks to DoesNotContain / MatchesRegex / IsNotEmpty.
test/Directory.Build.props Enables MSTest “Recommended” analyzer mode and adds MSTEST warning suppression.
test/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests/EventLogSessionContextTests.cs Converts boolean comparisons to AreEqual / empties to IsEmpty.
test/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests/EventLogDataCollectorTests.cs Converts map size checks to IsEmpty/HasCount.
test/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests/EventLogContainerTests.cs Converts “count > 0” to Assert.IsGreaterThan.
test/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector.UnitTests/CollectorNameValueConfigurationManagerTests.cs Converts count checks to IsEmpty.
Comments suppressed due to low confidence (10)

test/vstest.console.UnitTests/ExecutorUnitTests.cs:1

  • These Assert.Contains/Assert.DoesNotContain calls use a predicate overload that is not available in MSTest in many target versions, and also appear to have the predicate/collection argument order reversed compared to common signatures. To avoid compile/runtime issues, switch to a supported pattern (e.g., Assert.IsTrue(mockOutput.Messages.Any(...)) / Assert.IsFalse(...) or the correct MSTest overload if present in your referenced MSTest version).
    test/vstest.console.UnitTests/ExecutorUnitTests.cs:1
  • These Assert.Contains/Assert.DoesNotContain calls use a predicate overload that is not available in MSTest in many target versions, and also appear to have the predicate/collection argument order reversed compared to common signatures. To avoid compile/runtime issues, switch to a supported pattern (e.g., Assert.IsTrue(mockOutput.Messages.Any(...)) / Assert.IsFalse(...) or the correct MSTest overload if present in your referenced MSTest version).
    test/vstest.console.UnitTests/ExecutorUnitTests.cs:1
  • These Assert.Contains/Assert.DoesNotContain calls use a predicate overload that is not available in MSTest in many target versions, and also appear to have the predicate/collection argument order reversed compared to common signatures. To avoid compile/runtime issues, switch to a supported pattern (e.g., Assert.IsTrue(mockOutput.Messages.Any(...)) / Assert.IsFalse(...) or the correct MSTest overload if present in your referenced MSTest version).
    test/vstest.console.UnitTests/ExecutorUnitTests.cs:1
  • These Assert.Contains/Assert.DoesNotContain calls use a predicate overload that is not available in MSTest in many target versions, and also appear to have the predicate/collection argument order reversed compared to common signatures. To avoid compile/runtime issues, switch to a supported pattern (e.g., Assert.IsTrue(mockOutput.Messages.Any(...)) / Assert.IsFalse(...) or the correct MSTest overload if present in your referenced MSTest version).
    test/vstest.console.UnitTests/ExecutorUnitTests.cs:1
  • These Assert.Contains/Assert.DoesNotContain calls use a predicate overload that is not available in MSTest in many target versions, and also appear to have the predicate/collection argument order reversed compared to common signatures. To avoid compile/runtime issues, switch to a supported pattern (e.g., Assert.IsTrue(mockOutput.Messages.Any(...)) / Assert.IsFalse(...) or the correct MSTest overload if present in your referenced MSTest version).
    test/vstest.console.UnitTests/ExecutorUnitTests.cs:1
  • These Assert.Contains/Assert.DoesNotContain calls use a predicate overload that is not available in MSTest in many target versions, and also appear to have the predicate/collection argument order reversed compared to common signatures. To avoid compile/runtime issues, switch to a supported pattern (e.g., Assert.IsTrue(mockOutput.Messages.Any(...)) / Assert.IsFalse(...) or the correct MSTest overload if present in your referenced MSTest version).
    test/Microsoft.TestPlatform.TestUtilities/SourceAssert.cs:1
  • The new Assert.Contains usages rely on a predicate-based overload. If the referenced MSTest assertion library does not provide this overload (or expects arguments in a different order), this will fail to compile or behave incorrectly. Consider rewriting these checks using Any(...) with Assert.IsTrue(...), or ensure you’re using the correct MSTest overload and argument order for predicate-based containment.
    test/Microsoft.TestPlatform.TestUtilities/SourceAssert.cs:1
  • The new Assert.Contains usages rely on a predicate-based overload. If the referenced MSTest assertion library does not provide this overload (or expects arguments in a different order), this will fail to compile or behave incorrectly. Consider rewriting these checks using Any(...) with Assert.IsTrue(...), or ensure you’re using the correct MSTest overload and argument order for predicate-based containment.
    test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs:1
  • This Assert.Contains call has the collection/value argument order reversed compared to other usage in the PR (and compared to common Contains(expected, collection) patterns). If this compiles due to an unexpected overload, it may still assert the opposite of what’s intended. Prefer Assert.Contains(Path.Combine(...), TestPluginCache.Instance.GetExtensionPaths(@\"Collector.dll\")) (or the MSTest-recommended equivalent) to make the intent unambiguous.
    test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs:1
  • Several tests add a TestContext property; here it’s non-nullable but not initialized (unlike other updated files that use = null!;). This can introduce nullable warnings and accidental null dereferences if the property is accessed before MSTest sets it. Consider initializing with = null!; (or making it nullable) consistently across the suite.


[TestClass]
public class Build : IntegrationTestBase
public static class Build
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MSTest typically requires [TestClass] types to be non-static for discovery/reflection rules, even if they only contain [AssemblyInitialize]. Converting this to a static class risks assembly initialization not running. Consider reverting to a non-static public class Build (it can still contain only static init/cleanup methods), or remove [TestClass] if MSTest supports assembly init in a non-test class in your setup.

Suggested change
public static class Build
public class Build

Copilot uses AI. Check for mistakes.

<PropertyGroup>
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
<NoWarn>$(NoWarn);MSTEST0001</NoWarn>
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling MSTestAnalysisMode=Recommended while globally suppressing MSTEST0001 can hide real issues across the entire test tree. If the suppression is only needed for a few known exceptions, prefer narrowing it (e.g., per-project, per-file via NoWarn in the specific csproj, or via #pragma where applicable) and add a short comment explaining why the suppression is necessary.

Suggested change
<NoWarn>$(NoWarn);MSTEST0001</NoWarn>
<NoWarn>$(NoWarn)</NoWarn>

Copilot uses AI. Check for mistakes.
https://github.com/dotnet/arcade/issues/15875
-->
<UseMSTestRunner>true</UseMSTestRunner>
<MSTestAnalysisMode>Recommended</MSTestAnalysisMode>
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling MSTestAnalysisMode=Recommended while globally suppressing MSTEST0001 can hide real issues across the entire test tree. If the suppression is only needed for a few known exceptions, prefer narrowing it (e.g., per-project, per-file via NoWarn in the specific csproj, or via #pragma where applicable) and add a short comment explaining why the suppression is necessary.

Copilot uses AI. Check for mistakes.
var options = connectionInfo.ToCommandLineOptions();

StringAssert.StartsWith(options, "--port 123 --endpoint 127.0.0.0:123 --role client");
Assert.StartsWith(options, "--port 123 --endpoint 127.0.0.0:123 --role client");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringAssert.StartsWith(actual, expected) Assert.StartsWith(expected, actual), you need to swap the parameters everywhere unless it was already done.

The MSTest v3 Assert methods use a different parameter order than the
classic APIs they replaced:

- Assert.StartsWith/EndsWith(expected, actual) vs
  StringAssert.StartsWith/EndsWith(value, substring)
- Assert.Contains/DoesNotContain(substring, value) vs
  StringAssert.Contains(value, substring) and
  Assert.IsTrue(value.Contains(substring))
- Assert.IsGreaterThan/IsLessThan(bound, value) vs
  Assert.IsTrue(value > bound)
- Assert.DoesNotEndWith(notExpected, actual) vs
  Assert.IsFalse(actual.EndsWith(notExpected))

All conversions from StringAssert.StartsWith/EndsWith,
Assert.IsTrue(x.Contains/EndsWith/StartsWith),
Assert.IsTrue(x > y), and Assert.IsFalse(x.Contains/EndsWith)
now have their parameters in the correct order.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 24, 2026 08:19
microsoft#15566)

Use a short-lived Mutex to serialize the build phase and a named
ManualReset EventWaitHandle to signal build completion. This lets the
second test assembly start running tests as soon as the build finishes,
instead of waiting for the first assembly's entire test run to complete.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd force-pushed the fix-mstest-analyzers branch from 9f158b9 to a55e193 Compare March 24, 2026 08:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 161 out of 161 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (15)

test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs:1

  • These assertions intend to validate portOutput < 0, but the argument order for Assert.IsLessThan appears reversed (it currently reads as 0 < portOutput). Swap the arguments so the 'actual' value (portOutput) is validated as less than 0.
    test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs:1
  • These assertions intend to validate portOutput < 0, but the argument order for Assert.IsLessThan appears reversed (it currently reads as 0 < portOutput). Swap the arguments so the 'actual' value (portOutput) is validated as less than 0.
    test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs:1
  • The original intent was to assert watch.ElapsedMilliseconds < connectionTimeout, but Assert.IsLessThan(connectionTimeout, watch.ElapsedMilliseconds) checks the opposite. Swap the arguments (or use a clearer assertion like comparing watch.ElapsedMilliseconds against connectionTimeout).
    test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs:1
  • The original intent was to assert watch.ElapsedMilliseconds < connectionTimeout, but Assert.IsLessThan(connectionTimeout, watch.ElapsedMilliseconds) checks the opposite. Swap the arguments (or use a clearer assertion like comparing watch.ElapsedMilliseconds against connectionTimeout).
    test/Microsoft.TestPlatform.TestUtilities/CodeCoverageAcceptanceTestBase.cs:1
  • This assertion is meant to validate coverage > expectedCoverage (i.e., actual coverage exceeds the minimum threshold), but the Assert.IsGreaterThan arguments appear reversed. Swap them so coverage is asserted greater than expectedCoverage.
    test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs:1
  • The IndexOf(...) checks appear to have inverted argument order for IsLessThan / IsGreaterThan. For example, IndexOf(...) < 0 should assert the IndexOf return value is less than 0 (not that 0 is less than the return value), and IndexOf(...) > 0 should assert the return value is greater than 0 (not the reverse). Please swap the arguments in these comparisons.
    test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs:1
  • The IndexOf(...) checks appear to have inverted argument order for IsLessThan / IsGreaterThan. For example, IndexOf(...) < 0 should assert the IndexOf return value is less than 0 (not that 0 is less than the return value), and IndexOf(...) > 0 should assert the return value is greater than 0 (not the reverse). Please swap the arguments in these comparisons.
    test/Microsoft.TestPlatform.ObjectModel.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs:1
  • These IndexOf assertions are likely inverted. IndexOf(...) >= 0 should assert the IndexOf result is >= 0, and IndexOf(...) < 0 should assert the result is < 0. With the current argument ordering, the assertions risk checking the opposite condition.
    test/Microsoft.TestPlatform.ObjectModel.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs:1
  • These IndexOf assertions are likely inverted. IndexOf(...) >= 0 should assert the IndexOf result is >= 0, and IndexOf(...) < 0 should assert the result is < 0. With the current argument ordering, the assertions risk checking the opposite condition.
    test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestResultTests.cs:1
  • These assertions are not validating the intended time window. To ensure StartTime/EndTime are close to 'now', compare the absolute difference (or assert the difference is between -10s and +10s). As written (and with the apparent argument order), the checks can pass/fail for the wrong reasons, especially when Subtract returns a negative duration.
    test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs:1
  • The argument order for Assert.Contains looks swapped here. Elsewhere in this file you use Assert.Contains(substring, actualString, message), but this call passes _standardTestOutput first and summaryStatus second, which would check whether summaryStatus contains the entire standard output. Swap the arguments so the expected summaryStatus substring is searched within _standardTestOutput.
    test/Microsoft.TestPlatform.Library.IntegrationTests/DeprecateExtensionsPathWarningTests.cs:1
  • The [TestClass] attribute was removed. If this class contains [TestMethod]s (or is intended to), MSTest will no longer discover/run them. Please restore [TestClass] (or confirm the class is intentionally not a test fixture).
    test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyBaseManagerTests.cs:1
  • The [TestClass] attribute was removed from this test fixture. If this file contains MSTest tests, they will no longer be discovered. Please restore [TestClass] (or convert to the appropriate MSTest discovery mechanism if intentional).
    test/datacollector.UnitTests/DataCollectionAttachmentManagerTests.cs:1
  • Several tests now rely on TestContext.CancellationToken. For consistency with other updated files (and to avoid potential null dereferences depending on runner initialization timing), consider initializing TestContext with = null!; (or making it nullable and guarding usage) the same way other test classes in this PR do.
    test/vstest.console.UnitTests/Processors/ParentProcessIdArgumentProcessorTests.cs:1
  • The assertion message says this validates priority relative to Port, but the test no longer compares against PortArgumentProcessorCapabilities. Either restore the comparison against Port (to keep the test’s original intent) or update the message to reflect the new invariant being tested.


var trxFilePaths = Directory.EnumerateFiles(TempDirectory.Path, trxFileNamePattern + "_net*.trx");
Assert.IsTrue(trxFilePaths.Count() > 1);
Assert.IsGreaterThan(1, trxFilePaths.Count());
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion intends to check trxFilePaths.Count() > 1, but Assert.IsGreaterThan(1, trxFilePaths.Count()) reads as 1 > count. Swap the arguments so the actual count is asserted greater than 1.

Suggested change
Assert.IsGreaterThan(1, trxFilePaths.Count());
Assert.IsGreaterThan(trxFilePaths.Count(), 1);

Copilot uses AI. Check for mistakes.
@nohwnd
Copy link
Copy Markdown
Member Author

nohwnd commented Mar 24, 2026

Analyzer fixes pushed directly to Amaury's branch (PR #15539). Build collision fix split into separate PR #15568. Closing this PR.

@nohwnd nohwnd closed this Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants