From 2bb6348f8a5bbcca6d1f029080988147f3059fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sat, 6 Jun 2026 01:35:45 +0200 Subject: [PATCH 1/2] test: add edge case tests for TestMethodShouldNotBeIgnoredAnalyzer (MSTEST0015) Add four new test cases that document and verify distinct behavioral edges of the MSTEST0015 analyzer: - WhenDataTestMethodIsIgnored_Diagnostic: [DataTestMethod] is a TestMethod derivative and should trigger MSTEST0015 when paired with [Ignore]. - WhenMultipleTestMethodsAndOnlyOneIsIgnored_DiagnosticOnlyForIgnoredMethod: only the method that bears [Ignore] receives the diagnostic; the un-ignored sibling method is clean. - WhenOnlyClassLevelIgnoreWithNoMethodLevelIgnore_NoDiagnostic: MSTEST0015 inspects method-level attributes only, so a class-level [Ignore] without any method-level [Ignore] does not fire. - WhenIgnoredTestMethodHasMessage_Diagnostic: providing a justification message in [Ignore("...")]] satisfies MSTEST0014 (IgnoreShouldHaveJustification) but MSTEST0015 still fires because the test remains ignored. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...stMethodShouldNotBeIgnoredAnalyzerTests.cs | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs index 9c66e4a8f0..635954a18c 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs @@ -99,4 +99,107 @@ await VerifyCS.VerifyAnalyzerAsync( .WithLocation(0) .WithArguments("MyTestMethod")); } + + [TestMethod] + public async Task WhenDataTestMethodIsIgnored_Diagnostic() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class MyTestClass + { + [Ignore] + [DataTestMethod] + [DataRow(1)] + public void {|#0:MyTestMethod|}(int value) + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + code, + VerifyCS.Diagnostic(TestMethodShouldNotBeIgnoredAnalyzer.TestMethodShouldNotBeIgnoredRule) + .WithLocation(0) + .WithArguments("MyTestMethod")); + } + + [TestMethod] + public async Task WhenMultipleTestMethodsAndOnlyOneIsIgnored_DiagnosticOnlyForIgnoredMethod() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class MyTestClass + { + [TestMethod] + public void NotIgnoredMethod() + { + } + + [Ignore] + [TestMethod] + public void {|#0:IgnoredMethod|}() + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + code, + VerifyCS.Diagnostic(TestMethodShouldNotBeIgnoredAnalyzer.TestMethodShouldNotBeIgnoredRule) + .WithLocation(0) + .WithArguments("IgnoredMethod")); + } + + [TestMethod] + public async Task WhenOnlyClassLevelIgnoreWithNoMethodLevelIgnore_NoDiagnostic() + { + // MSTEST0015 only checks for [Ignore] on the method itself. + // A class-level [Ignore] silences the whole class but is not flagged by this rule. + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + [Ignore] + public class MyTestClass + { + [TestMethod] + public void MyTestMethod() + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } + + [TestMethod] + public async Task WhenIgnoredTestMethodHasMessage_Diagnostic() + { + // MSTEST0015 fires even when [Ignore] has a justification message. + // The presence of a message satisfies MSTEST0014 (IgnoreShouldHaveJustification), + // but the method is still ignored and MSTEST0015 still applies. + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class MyTestClass + { + [Ignore("Tracked by #12345")] + [TestMethod] + public void {|#0:MyTestMethod|}() + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync( + code, + VerifyCS.Diagnostic(TestMethodShouldNotBeIgnoredAnalyzer.TestMethodShouldNotBeIgnoredRule) + .WithLocation(0) + .WithArguments("MyTestMethod")); + } } From 1762d0005eeb310c739b22732f9bc0125338fae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 7 Jun 2026 09:56:29 +0200 Subject: [PATCH 2/2] Fix ignore justification analyzer ID in MSTEST0015 test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../TestMethodShouldNotBeIgnoredAnalyzerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs index 635954a18c..88f0c0825a 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs @@ -180,7 +180,7 @@ public void MyTestMethod() public async Task WhenIgnoredTestMethodHasMessage_Diagnostic() { // MSTEST0015 fires even when [Ignore] has a justification message. - // The presence of a message satisfies MSTEST0014 (IgnoreShouldHaveJustification), + // The presence of a message satisfies MSTEST0066 (IgnoreShouldHaveJustification), // but the method is still ignored and MSTEST0015 still applies. string code = """ using Microsoft.VisualStudio.TestTools.UnitTesting;