Skip to content

Update Mono.Linker.Tests to MSTest#126412

Merged
akoeplinger merged 3 commits intomainfrom
dev/ygerges/mstest
Apr 7, 2026
Merged

Update Mono.Linker.Tests to MSTest#126412
akoeplinger merged 3 commits intomainfrom
dev/ygerges/mstest

Conversation

@Youssef1313
Copy link
Copy Markdown
Member

@Youssef1313 Youssef1313 commented Apr 1, 2026

Related to dotnet/arcade#16428

Copilot AI review requested due to automatic review settings April 1, 2026 15:12
@github-actions github-actions bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Apr 1, 2026
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Apr 1, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.

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

This PR updates the Mono.Linker.Tests test project to use MSTest instead of NUnit.

Changes:

  • Switches test framework attributes/usings from NUnit to MSTest across multiple test files.
  • Updates test case data feeding from NUnit TestCaseSource/TestCaseData to MSTest DynamicData/DataRow patterns.
  • Changes project configuration to use the MSTest test runner and updates assembly-level parallelization settings.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/tools/illink/test/Trimming.Tests.Shared/TestCaseSandbox.cs Updates documentation text to refer to MSTest instead of NUnit.
src/tools/illink/test/Mono.Linker.Tests/Tests/TestFrameworkRulesAndConventions.cs Converts fixture/method attributes to MSTest.
src/tools/illink/test/Mono.Linker.Tests/Tests/PreserveActionComparisonTests.cs Converts parameterized test attributes to MSTest DataRow.
src/tools/illink/test/Mono.Linker.Tests/Tests/ParseResponseFileLinesTests.cs Converts test attributes to MSTest.
src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs Converts test attributes/usings to MSTest.
src/tools/illink/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs Converts non-parallelizable/parameterized tests to MSTest equivalents.
src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs Converts parameterized tests to MSTest DynamicData.
src/tools/illink/test/Mono.Linker.Tests/Tests/CodeOptimizationsSettingsTests.cs Converts test attributes/usings to MSTest.
src/tools/illink/test/Mono.Linker.Tests/Tests/AnnotationStoreTest.cs Converts to MSTest [TestClass]/[TestMethod].
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs Replaces NUnit using with MSTest using in the test runner integration.
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs Replaces NUnit using with MSTest using.
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs Updates comments referring to test framework attributes/data sources.
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs Replaces NUnit using with MSTest using.
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/MemberAssertionsCollector.cs Changes member assertion data generation to MSTest data row types.
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILVerifier.cs Replaces NUnit using with MSTest using.
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILChecker.cs Replaces NUnit using with MSTest using.
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILCompiler.cs Replaces NUnit using with MSTest using.
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs Replaces NUnit using with MSTest using.
src/tools/illink/test/Mono.Linker.Tests/TestCases/TestSuites.cs Converts suite runners to MSTest DynamicData.
src/tools/illink/test/Mono.Linker.Tests/TestCases/TestDatabase.cs Converts test case enumeration helpers from NUnit to MSTest data row patterns.
src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs Converts individual tests to MSTest.
src/tools/illink/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj Switches TestRunnerName from NUnit to MSTest.
src/tools/illink/test/Mono.Linker.Tests/AssemblyInfo.cs Replaces NUnit assembly parallelization with MSTest [assembly: Parallelize].
Comments suppressed due to low confidence (3)

src/tools/illink/test/Mono.Linker.Tests/Tests/PreserveActionComparisonTests.cs:30

  • This test class is switched to MSTest attributes, but the assertions still use NUnit's constraint model (e.g., Assert.That / Is.EqualTo). These APIs aren't available in MSTest and will fail to compile unless a compatibility layer is provided; replace with MSTest assertions (e.g., Assert.AreEqual / Assert.IsTrue, etc.).
        public void VerifyBehaviorOfChoosePreserveActionWhichPreservesTheMost(TypePreserve left, TypePreserve right, TypePreserve expected)
        {
            Assert.That(expected, Is.EqualTo(AnnotationStore.ChoosePreserveActionWhichPreservesTheMost(left, right)));
            Assert.That(expected, Is.EqualTo(AnnotationStore.ChoosePreserveActionWhichPreservesTheMost(right, left)));

src/tools/illink/test/Mono.Linker.Tests/TestCases/TestSuites.cs:61

  • MSTest doesn't have Assert.Ignore(). If these tests need to be skipped at runtime, use an MSTest-supported mechanism (e.g., throw AssertInconclusiveException / call Assert.Inconclusive, or use an [Ignore] attribute with a condition handled by the runner).
        {
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                Assert.Ignore("These tests are not valid when trimming .NET Framework");

src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs:50

  • Assert.NotNull is not an MSTest Assert API (MSTest uses Assert.IsNotNull). This will fail to compile after the NUnit->MSTest switch; update to the MSTest assertion method.
        public static void CheckUniqueParsedString(IMemberDefinition member, string input)
        {
            var module = (member as TypeDefinition)?.Module ?? member.DeclaringType?.Module;
            Assert.NotNull(module);
            var parseResults = DocumentationSignatureParser.GetMembersForDocumentationSignature(input, module, new TestResolver());
            Assert.AreEqual(1, parseResults.Count());
            Assert.AreEqual(member, parseResults.First());

Copilot AI review requested due to automatic review settings April 1, 2026 15:27
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 30 out of 30 changed files in this pull request and generated 23 comments.

Comments suppressed due to low confidence (1)

src/tools/illink/test/Mono.Linker.Tests/Tests/PreserveActionComparisonTests.cs:30

  • This test still uses NUnit constraint assertions (Assert.That(..., Is.EqualTo(...))), but the file now references MSTest. Assert.That/Is won't compile under MSTest; replace these with MSTest asserts (e.g., Assert.AreEqual(...)).
        public void VerifyBehaviorOfChoosePreserveActionWhichPreservesTheMost(TypePreserve left, TypePreserve right, TypePreserve expected)
        {
            Assert.That(expected, Is.EqualTo(AnnotationStore.ChoosePreserveActionWhichPreservesTheMost(left, right)));
            Assert.That(expected, Is.EqualTo(AnnotationStore.ChoosePreserveActionWhichPreservesTheMost(right, left)));

@github-actions

This comment has been minimized.

Copilot AI review requested due to automatic review settings April 1, 2026 15:46
@Youssef1313 Youssef1313 force-pushed the dev/ygerges/mstest branch 2 times, most recently from dcbfb1a to f61e904 Compare April 1, 2026 15:52
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 23 out of 23 changed files in this pull request and generated 4 comments.

@github-actions

This comment has been minimized.

Copilot AI review requested due to automatic review settings April 1, 2026 16:11
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 23 out of 23 changed files in this pull request and generated 5 comments.

Copilot AI review requested due to automatic review settings April 1, 2026 17:28
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 23 out of 23 changed files in this pull request and generated 8 comments.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Note

This review was generated by Copilot.

🤖 Copilot Code Review — PR #126412

Holistic Assessment

Motivation: This PR migrates Mono.Linker.Tests from NUnit to MSTest as part of the broader dotnet/runtime effort to standardize on MSTest. The motivation is clear and the change is justified.

Approach: The migration is thorough and mechanical — attribute substitutions ([TestFixture][TestClass], [Test][TestMethod], [TestCaseSource][DynamicData]), assertion API changes, and data source type changes (TestCaseDataTestDataRow<T>). The approach is sound.

Summary: ✅ LGTM. The migration is comprehensive and correct. All NUnit assertion methods are properly mapped to their MSTest equivalents with correct argument ordering (verified against the MSTest source). Two minor style observations noted below, neither blocking.


Detailed Findings

✅ Assertion API Correctness — Verified against MSTest source

All assertion conversions were verified against the actual MSTest source code:

  • Assert.IsLessThan(expectedMaxLines, lineCount, msg) (IndividualTests.cs:198): Correct. MSTest signature is IsLessThan(T upperBound, T value) — asserts value < upperBound, so this correctly asserts lineCount < expectedMaxLines.
  • Assert.Contains(item, collection) / Assert.DoesNotContain(item, collection) (ResultChecker.cs:841,849): Correct. MSTest signature is Contains<T>(T expected, IEnumerable<T> collection).
  • Assert.IsEmpty(collection, msg) (ResultChecker.cs:864, TestFrameworkRulesAndConventions.cs): Correct. Exists in Assert.Count.cs.
  • Assert.Inconclusive replacing NUnit Assert.Ignore: Correct MSTest equivalent.
  • UnitTestAssertException replacing NUnit's individual exception types (TestRunner.cs:32): Correct — MSTest's base exception class covers all assertion failure types.

✅ Data Source Migration — Correct

  • [TestCaseSource(typeof(T), nameof(...))][DynamicData(nameof(...), typeof(T))]: Argument order correctly swapped (MSTest puts name first, type second).
  • [DynamicData(nameof(Method), new object[] { typeof(T) })] for data source methods that take parameters: Uses the MSTest constructor for passing method arguments.
  • TestCaseDataTestDataRow<T> with tuple unpacking for multi-parameter test methods: Correct.

✅ Attribute Migration — Complete

All NUnit attributes properly mapped: [TestFixture][TestClass], [Test][TestMethod], [SetUp][TestInitialize], [TestCase][DataRow], [NonParallelizable][DoNotParallelize], [Parallelizable][Parallelize]. No remaining NUnit references in .cs files.

💡 Using Directive Ordering — MemberAssertionsCollector.cs

In MemberAssertionsCollector.cs (lines 8-9), the Microsoft.VisualStudio.TestTools.UnitTesting using comes after Mono.Cecil. Alphabetically, Microsoft should sort before Mono. All other files in this PR have the correct ordering.

// Current (lines 8-9):
using Mono.Cecil;
using Microsoft.VisualStudio.TestTools.UnitTesting;

// Suggested:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mono.Cecil;

💡 CollectionAssert.AreEquivalent Argument Order — Convention

Several CollectionAssert.AreEquivalent calls place the actual value first and expected second (e.g., IndividualTests.cs:78-80, ResultChecker.cs:831-833). MSTest's signature is AreEquivalent(ICollection expected, ICollection actual). Since AreEquivalent checks bidirectional membership, this doesn't affect correctness — only error message clarity on failure. Non-blocking, but worth noting for consistency.

Generated by Code Review for issue #126412 ·

Copy link
Copy Markdown
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

This change looks ok to me, but I would prefer to migrate to xunit instead for consistency, did you consider that?

@sbomer sbomer requested a review from a team April 2, 2026 16:37
@Youssef1313
Copy link
Copy Markdown
Member Author

I considered that, but it's way easier to move to MSTest as the API surface is quite close to NUnit, while very different for xUnit and will require more efforts.

Copy link
Copy Markdown
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

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

LGTM if we just want to drop NUnit asap. Might be worth a shot to see if copilot could migrate to XUnit once this is in, though.

@akoeplinger
Copy link
Copy Markdown
Member

/ba-g failing jobs don't run this test suite, unrelated

@akoeplinger akoeplinger merged commit 7e2ee62 into main Apr 7, 2026
93 of 96 checks passed
@akoeplinger akoeplinger deleted the dev/ygerges/mstest branch April 7, 2026 11:05
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants