From 9b46d3b1c853e0106f58c994481061ab17602d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 1 Jun 2026 01:34:30 +0200 Subject: [PATCH] test: add abstract method edge case test for MSTEST0041 (UseDeploymentItemWithTestMethodOrTestClass) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...emWithTestMethodOrTestClassAnalyzerTests.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests.cs index e0fa42c540..701b900dfa 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests.cs @@ -136,4 +136,22 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + + [TestMethod] + public async Task WhenAbstractMethodHasDeploymentItemWithoutTestMethod_Diagnostic() + { + // Abstract classes are skipped (DeploymentItem is inherited), but abstract methods are not. + // An abstract method with [DeploymentItem] but no [TestMethod] is flagged as misuse. + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + public abstract class MyBaseClass + { + [DeploymentItem("")] + public abstract void [|SomeMethod|](); + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } }