From abe854a5bf09973a4235f967ef000a82ff47fea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 14 Jul 2026 09:46:54 +0200 Subject: [PATCH 1/2] test: add MSTEST0035 tests for custom RetryBaseAttribute subclasses Add four tests covering the Inherits() path for custom derived RetryBaseAttribute subclasses in UseRetryWithTestMethodAnalyzer: - WhenNonTestMethodHasCustomDerivedRetryAttribute_Diagnostic - WhenTestMethodHasCustomDerivedRetryAttribute_NoDiagnostic - WhenNonTestClassHasCustomDerivedRetryAttribute_Diagnostic - WhenTestClassHasCustomDerivedRetryAttribute_NoDiagnostic These tests confirm that user-defined RetryBaseAttribute subclasses are correctly handled by the Inherits() check in the analyzer. Fixes #9918 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: efa48d3b-7307-4c38-a477-815b089201c5 --- .../UseRetryWithTestMethodAnalyzerTests.cs | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseRetryWithTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseRetryWithTestMethodAnalyzerTests.cs index fae5fca4d71..6efa32e3cb0 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseRetryWithTestMethodAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseRetryWithTestMethodAnalyzerTests.cs @@ -265,4 +265,115 @@ public class MyHelper await VerifyCS.VerifyCodeFixAsync(code, code); } + + [TestMethod] + public async Task WhenNonTestMethodHasCustomDerivedRetryAttribute_Diagnostic() + { + // The analyzer uses Inherits() to detect RetryBaseAttribute subclasses. + // A user-defined subclass of RetryBaseAttribute on a non-test method should trigger the diagnostic. + string code = """ + #pragma warning disable MSTESTEXP + using System.Threading.Tasks; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + public class MyRetryAttribute : RetryBaseAttribute + { + protected override Task ExecuteAsync(RetryContext context) => Task.FromResult(new RetryResult()); + } + #pragma warning restore MSTESTEXP + + [TestClass] + public class MyTestClass + { + [MyRetry] + public void [|M|]() + { + } + } + """; + + await VerifyCS.VerifyCodeFixAsync(code, code); + } + + [TestMethod] + public async Task WhenTestMethodHasCustomDerivedRetryAttribute_NoDiagnostic() + { + // A user-defined RetryBaseAttribute subclass on an actual test method should NOT trigger the diagnostic. + string code = """ + #pragma warning disable MSTESTEXP + using System.Threading.Tasks; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + public class MyRetryAttribute : RetryBaseAttribute + { + protected override Task ExecuteAsync(RetryContext context) => Task.FromResult(new RetryResult()); + } + #pragma warning restore MSTESTEXP + + [TestClass] + public class MyTestClass + { + [TestMethod] + [MyRetry] + public void M() + { + } + } + """; + + await VerifyCS.VerifyCodeFixAsync(code, code); + } + + [TestMethod] + public async Task WhenNonTestClassHasCustomDerivedRetryAttribute_Diagnostic() + { + // A user-defined RetryBaseAttribute subclass on a non-test class should trigger the diagnostic. + string code = """ + #pragma warning disable MSTESTEXP + using System.Threading.Tasks; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + public class MyRetryAttribute : RetryBaseAttribute + { + protected override Task ExecuteAsync(RetryContext context) => Task.FromResult(new RetryResult()); + } + #pragma warning restore MSTESTEXP + + [MyRetry] + public class [|MyClass|] + { + } + """; + + await VerifyCS.VerifyCodeFixAsync(code, code); + } + + [TestMethod] + public async Task WhenTestClassHasCustomDerivedRetryAttribute_NoDiagnostic() + { + // A user-defined RetryBaseAttribute subclass on an actual test class should NOT trigger the diagnostic. + string code = """ + #pragma warning disable MSTESTEXP + using System.Threading.Tasks; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + public class MyRetryAttribute : RetryBaseAttribute + { + protected override Task ExecuteAsync(RetryContext context) => Task.FromResult(new RetryResult()); + } + #pragma warning restore MSTESTEXP + + [TestClass] + [MyRetry] + public class MyTestClass + { + [TestMethod] + public void M() + { + } + } + """; + + await VerifyCS.VerifyCodeFixAsync(code, code); + } } From d1f49447816dd8d2a916856fcdcfa1a3581fe4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 14 Jul 2026 09:47:26 +0200 Subject: [PATCH 2/2] Update .xlf files to be in sync with .resx Regenerated via UpdateXlf. The last localized check-in added translations for 'GlobalTestFixtureShouldBeValidClassLayout' (fr) and 'SlowTestStillRunning' (ru) that XliffTasks rejects (placeholder mismatch), breaking the build with "xlf is out-of-date with resx". UpdateXlf resets those two units to state="new" so the build passes; they will be re-translated on the next localization pass. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4350f662-0e5d-4e05-b156-1ef619da3b9e --- .../MSTest.Analyzers/xlf/Resources.fr.xlf | 30 +++++++++---------- .../xlf/GitHubActionsResources.ru.xlf | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf index fd6b6efa2a9..398d0b548a5 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf @@ -563,21 +563,21 @@ The type declaring these methods should also respect the following rules: -The class should be 'public' -The class should be marked with '[TestClass]' (or a derived attribute) -the class should not be generic. - Les méthodes marquées par « [GlobalTestInitialize] » ou « [GlobalTestCleanup] » doivent respecter le schéma suivant pour être valides : -- elle ne peut pas être déclarée dans une classe générique -– elle doit être « public » -– cela devrait être « static ». -– cela ne devrait pas être « async void ». -– il ne doit pas s'agir d'une méthode spéciale (finaliseur, opérateur...). -– elle ne doit pas être générique -– il doit prendre un paramètre de type « TestContext » -– le type de retour doit être « void », « Task » ou « ValueTask ». -{0} -Le type déclarant ces méthodes doit également respecter les règles suivantes : -- le type doit être une classe -- la classe doit être « public » --La classe doit être marquée avec « [TestClass] » (ou un attribut dérivé). -- la classe ne doit pas être générique. + Methods marked with '[GlobalTestInitialize]' or '[GlobalTestCleanup]' should follow the following layout to be valid: +-it can't be declared on a generic class +-it should be 'public' +-it should be 'static' +-it should not be 'async void' +-it should not be a special method (finalizer, operator...). +-it should not be generic +-it should take one parameter of type 'TestContext' +-return type should be 'void', 'Task' or 'ValueTask' + +The type declaring these methods should also respect the following rules: +-The type should be a class +-The class should be 'public' +-The class should be marked with '[TestClass]' (or a derived attribute) +-the class should not be generic. {Locked="[GlobalTestInitialize]"}{Locked="[GlobalTestCleanup]"}{Locked="[TestClass]"}{Locked="TestContext"}{Locked="ValueTask"}{Locked="Task"}{Locked="public"}{Locked="static"}{Locked="void"}{Locked="async void"}{Locked="async"}{Locked="class"} diff --git a/src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/xlf/GitHubActionsResources.ru.xlf b/src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/xlf/GitHubActionsResources.ru.xlf index 44bc6fcda06..d1245f23650 100644 --- a/src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/xlf/GitHubActionsResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/xlf/GitHubActionsResources.ru.xlf @@ -74,7 +74,7 @@ {0} still running after {1}s - {0} все еще выполняется через {0} с + {0} still running after {1}s {0} is the fully qualified test name, {1} is the elapsed seconds.