From 7a364d47cfeda223d749f1ae845828452ab887e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 19 Jan 2026 09:50:10 +0100 Subject: [PATCH 1/4] Rework MSTEST0016 message and description --- src/Analyzers/MSTest.Analyzers/Resources.resx | 13 +++++++++++-- .../MSTest.Analyzers/xlf/Resources.cs.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.de.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.es.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.fr.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.it.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.ja.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.ko.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.pl.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.pt-BR.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.ru.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.tr.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.zh-Hans.xlf | 17 +++++++++++++---- .../MSTest.Analyzers/xlf/Resources.zh-Hant.xlf | 17 +++++++++++++---- 14 files changed, 180 insertions(+), 54 deletions(-) diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx index 843c399635..163432b37b 100644 --- a/src/Analyzers/MSTest.Analyzers/Resources.resx +++ b/src/Analyzers/MSTest.Analyzers/Resources.resx @@ -323,10 +323,19 @@ The type declaring these methods should also respect the following rules: Test classes should have valid layout - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. Test class should have test method diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf index d040ccf7c1..4020a98b72 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf @@ -704,13 +704,22 @@ Typ deklarující tyto metody by měl také respektovat následující pravidla: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - Testovací třída by měla mít aspoň jednu testovací metodu nebo by měla být static s metodami s označením [AssemblyInitialize] a/nebo [AssemblyCleanup]. + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + Testovací třída by měla mít aspoň jednu testovací metodu nebo by měla být static s metodami s označením [AssemblyInitialize] a/nebo [AssemblyCleanup]. - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - Testovací třída {0} by měla mít aspoň jednu testovací metodu nebo by měla být static s metodami s označením [AssemblyInitialize] a/nebo [AssemblyCleanup]. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + Testovací třída {0} by měla mít aspoň jednu testovací metodu nebo by měla být static s metodami s označením [AssemblyInitialize] a/nebo [AssemblyCleanup]. diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf index 051f8ace98..dbbcb8c70a 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf @@ -705,13 +705,22 @@ Der Typ, der diese Methoden deklariert, sollte auch die folgenden Regeln beachte - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - Die Testklasse muss mindestens eine Testmethode aufweisen oder "statisch" sein, wenn Methoden mit "[AssemblyInitialize]" und/oder "[AssemblyCleanup]" markiert sind. + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + Die Testklasse muss mindestens eine Testmethode aufweisen oder "statisch" sein, wenn Methoden mit "[AssemblyInitialize]" und/oder "[AssemblyCleanup]" markiert sind. - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - Die Testklasse "{0}" muss mindestens eine Testmethode aufweisen oder "statisch" sein, wenn Methoden mit "[AssemblyInitialize]" und/oder "[AssemblyCleanup]" markiert sind. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + Die Testklasse "{0}" muss mindestens eine Testmethode aufweisen oder "statisch" sein, wenn Methoden mit "[AssemblyInitialize]" und/oder "[AssemblyCleanup]" markiert sind. diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf index b8b97fdd39..c8b02ddf79 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf @@ -704,13 +704,22 @@ El tipo que declara estos métodos también debe respetar las reglas siguientes: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - La clase de prueba debe tener al menos un método de prueba o ser "static" con métodos marcados por "[AssemblyInitialize]" o "[AssemblyCleanup]". + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + La clase de prueba debe tener al menos un método de prueba o ser "static" con métodos marcados por "[AssemblyInitialize]" o "[AssemblyCleanup]". - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - La clase de prueba "{0}" debe tener al menos un método de prueba o ser "static" con métodos marcados por "[AssemblyInitialization]" o "[AssemblyCleanup]" + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + La clase de prueba "{0}" debe tener al menos un método de prueba o ser "static" con métodos marcados por "[AssemblyInitialization]" o "[AssemblyCleanup]" diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf index c82c4169b1..197c564ca8 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf @@ -704,13 +704,22 @@ Le type déclarant ces méthodes doit également respecter les règles suivantes - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - La classe de test doit avoir au moins une méthode de test ou être « statique » avec une ou plusieurs méthodes marquées par « [AssemblyInitialize] » et/ou « [AssemblyCleanup] ». + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + La classe de test doit avoir au moins une méthode de test ou être « statique » avec une ou plusieurs méthodes marquées par « [AssemblyInitialize] » et/ou « [AssemblyCleanup] ». - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - La classe de test '{0}' doit avoir au moins une méthode de test ou être « statique » avec une ou plusieurs méthodes marquées par « [AssemblyInitialize] » et/ou « [AssemblyCleanup] » + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + La classe de test '{0}' doit avoir au moins une méthode de test ou être « statique » avec une ou plusieurs méthodes marquées par « [AssemblyInitialize] » et/ou « [AssemblyCleanup] » diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf index bde2b3f237..f2928367ef 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf @@ -704,13 +704,22 @@ Anche il tipo che dichiara questi metodi deve rispettare le regole seguenti: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - La classe di test deve avere almeno un metodo di test o essere 'static' con metodi contrassegnati da '[AssemblyInitialize]' e/o '[AssemblyCleanup]'. + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + La classe di test deve avere almeno un metodo di test o essere 'static' con metodi contrassegnati da '[AssemblyInitialize]' e/o '[AssemblyCleanup]'. - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - La classe di test '{0}' deve avere almeno un metodo di test o essere 'static' con metodi contrassegnati da '[AssemblyInitializate]' e/o '[AssemblyCleanup]' + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + La classe di test '{0}' deve avere almeno un metodo di test o essere 'static' con metodi contrassegnati da '[AssemblyInitializate]' e/o '[AssemblyCleanup]' diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf index 7bd1ccccb7..5e5c8b6bc2 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf @@ -704,13 +704,22 @@ The type declaring these methods should also respect the following rules: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - テスト クラスには、少なくとも 1 つのテスト メソッドがあるか、'[AssemblyInitialize]' または '[AssemblyCleanup]' によってマークされたメソッドを含む 'static' である必要があります。 + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + テスト クラスには、少なくとも 1 つのテスト メソッドがあるか、'[AssemblyInitialize]' または '[AssemblyCleanup]' によってマークされたメソッドを含む 'static' である必要があります。 - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - テスト クラス '{0}' には、少なくとも 1 つのテスト メソッドがあるか、'[AssemblyInitialize]' または '[AssemblyCleanup]' によってマークされたメソッドを含む 'static' である必要があります。 + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + テスト クラス '{0}' には、少なくとも 1 つのテスト メソッドがあるか、'[AssemblyInitialize]' または '[AssemblyCleanup]' によってマークされたメソッドを含む 'static' である必要があります。 diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf index f7cf65ca16..921b7b9cf4 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf @@ -704,13 +704,22 @@ The type declaring these methods should also respect the following rules: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - 테스트 클래스에는 하나 이상의 테스트 메서드가 있거나 '[AssemblyInitialize]' 및/또는 '[AssemblyCleanup]'으로 표시된 메서드가 있는 'static'이어야 합니다. + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + 테스트 클래스에는 하나 이상의 테스트 메서드가 있거나 '[AssemblyInitialize]' 및/또는 '[AssemblyCleanup]'으로 표시된 메서드가 있는 'static'이어야 합니다. - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - 테스트 클래스 '{0}'에는 하나 이상의 테스트 메서드가 있거나 '[AssemblyInitialize]' 및/또는 '[AssemblyCleanup]'으로 표시된 메서드가 있는 'static'이어야 합니다. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + 테스트 클래스 '{0}'에는 하나 이상의 테스트 메서드가 있거나 '[AssemblyInitialize]' 및/또는 '[AssemblyCleanup]'으로 표시된 메서드가 있는 'static'이어야 합니다. diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf index 9b3813056c..335a149c02 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf @@ -704,13 +704,22 @@ Typ deklarujący te metody powinien również przestrzegać następujących regu - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - Klasa testowa powinna mieć co najmniej jedną metodę testową lub być „statyczna” z metodami oznaczonymi jako „[AssemblyInitialize]” i/lub „[AssemblyCleanup]”. + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + Klasa testowa powinna mieć co najmniej jedną metodę testową lub być „statyczna” z metodami oznaczonymi jako „[AssemblyInitialize]” i/lub „[AssemblyCleanup]”. - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - Klasa „{0}” testowa powinna mieć co najmniej jedną metodę testową lub być „statyczna” z metodami oznaczonymi jako „[AssemblyInitialize]” i/lub „[AssemblyCleanup]”. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + Klasa „{0}” testowa powinna mieć co najmniej jedną metodę testową lub być „statyczna” z metodami oznaczonymi jako „[AssemblyInitialize]” i/lub „[AssemblyCleanup]”. diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf index 73c97b68e5..a39a4cbfda 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf @@ -704,13 +704,22 @@ O tipo que declara esses métodos também deve respeitar as seguintes regras: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - A classe de teste deve ter pelo menos um método de teste ou ser 'estática' com métodos marcados por '[AssemblyInitialize]' e/ou '[AssemblyCleanup]'. + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + A classe de teste deve ter pelo menos um método de teste ou ser 'estática' com métodos marcados por '[AssemblyInitialize]' e/ou '[AssemblyCleanup]'. - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - A classe de teste '{0}' deve ter pelo menos um método de teste ou ser 'estática' com métodos marcados por '[AssemblyInitialize]' e/ou '[AssemblyCleanup]'. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + A classe de teste '{0}' deve ter pelo menos um método de teste ou ser 'estática' com métodos marcados por '[AssemblyInitialize]' e/ou '[AssemblyCleanup]'. diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf index 20ea77f181..177f711e4a 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf @@ -710,13 +710,22 @@ The type declaring these methods should also respect the following rules: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - Тестовый класс должен содержать хотя бы один тестовый метод или быть "статическим" с методами, отмеченными "[AssemblyInitialize]" и (или) "[AssemblyCleanup]". + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + Тестовый класс должен содержать хотя бы один тестовый метод или быть "статическим" с методами, отмеченными "[AssemblyInitialize]" и (или) "[AssemblyCleanup]". - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - Тестовый класс "{0}" должен содержать хотя бы один тестовый метод или быть "статическим" с методами, отмеченными "[AssemblyInitialize]" и (или) "[AssemblyCleanup]" + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + Тестовый класс "{0}" должен содержать хотя бы один тестовый метод или быть "статическим" с методами, отмеченными "[AssemblyInitialize]" и (или) "[AssemblyCleanup]" diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf index 8da1950c54..00ca4dff79 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf @@ -705,13 +705,22 @@ Bu metotları bildiren türün ayrıca aşağıdaki kurallara uyması gerekir: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - Test sınıfı en az bir test yöntemine sahip olmalıdır veya '[AssemblyInitialize]' ve/veya '[AssemblyCleanup]' ile işaretlenen yöntemlere sahip 'static' olmalıdır. + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + Test sınıfı en az bir test yöntemine sahip olmalıdır veya '[AssemblyInitialize]' ve/veya '[AssemblyCleanup]' ile işaretlenen yöntemlere sahip 'static' olmalıdır. - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - '{0}' test sınıfı en az bir test yöntemine sahip olmalıdır veya '[AssemblyInitialize]' ve/veya '[AssemblyCleanup]' ile işaretlenen yöntemlere sahip 'static' olmalıdır + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + '{0}' test sınıfı en az bir test yöntemine sahip olmalıdır veya '[AssemblyInitialize]' ve/veya '[AssemblyCleanup]' ile işaretlenen yöntemlere sahip 'static' olmalıdır diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf index 8260548da4..7943c58b96 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf @@ -704,13 +704,22 @@ The type declaring these methods should also respect the following rules: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - 测试类应至少有一个测试方法,或者应为 "static" 且方法由 "[AssemblyInitialize]" 和/或 "[AssemblyCleanup]" 标记。 + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + 测试类应至少有一个测试方法,或者应为 "static" 且方法由 "[AssemblyInitialize]" 和/或 "[AssemblyCleanup]" 标记。 - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - 测试类 "{0}" 应至少有一个测试方法,或者应为 "static" 且方法由 "[AssemblyInitialize]" 和/或 "[AssemblyCleanup]" 标记 + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + 测试类 "{0}" 应至少有一个测试方法,或者应为 "static" 且方法由 "[AssemblyInitialize]" 和/或 "[AssemblyCleanup]" 标记 diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf index ded18e6aaa..70cef89bf9 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf @@ -704,13 +704,22 @@ The type declaring these methods should also respect the following rules: - Test class should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]'. - 測試類別至少應有一個測試方法或是 'static',而其方法是以 '[AssemblyInitialization]' 和/或 '[AssemblyCleanup]'標示。 + Test classes (classes marked with '[TestClass]' attribute) should contain at least one test method. + +A test method is any method marked with '[TestMethod]' or an attribute that derives from it (for example, custom test method attributes). The analyzer also considers test methods defined in base classes. + +Exception: A 'static' test class is valid without test methods if it contains at least one method marked with '[AssemblyInitialize]', '[AssemblyCleanup]', '[GlobalTestInitialize]', or '[GlobalTestCleanup]'. + +Common scenarios where this rule triggers: +- The class was intended to be a base class containing shared test setup but was incorrectly marked with '[TestClass]'. Consider removing the '[TestClass]' attribute from base classes. +- Test methods were accidentally removed or commented out. +- The class contains only helper methods and should not be marked as a test class. + 測試類別至少應有一個測試方法或是 'static',而其方法是以 '[AssemblyInitialization]' 和/或 '[AssemblyCleanup]'標示。 - Test class '{0}' should have at least one test method or be 'static' with method(s) marked by '[AssemblyInitialize]' and/or '[AssemblyCleanup]' - 測試類別 '{0}' 至少應有一個測試方法或是 'static',而其方法是以 '[AssemblyInitialization]' 和/或 '[AssemblyCleanup]'標示。 + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + 測試類別 '{0}' 至少應有一個測試方法或是 'static',而其方法是以 '[AssemblyInitialization]' 和/或 '[AssemblyCleanup]'標示。 From 8fd8816ab4d7e6c2e562c015f366e26d71085b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 21 Jan 2026 13:53:20 +0100 Subject: [PATCH 2/4] Address review comment --- src/Analyzers/MSTest.Analyzers/Resources.resx | 3 ++ .../TestClassShouldHaveTestMethodAnalyzer.cs | 43 ++++++++++++++++--- .../MSTest.Analyzers/xlf/Resources.cs.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.de.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.es.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.fr.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.it.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.ja.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.ko.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.pl.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.pt-BR.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.ru.xlf | 5 +++ .../MSTest.Analyzers/xlf/Resources.tr.xlf | 5 +++ .../xlf/Resources.zh-Hans.xlf | 5 +++ .../xlf/Resources.zh-Hant.xlf | 5 +++ ...tClassShouldHaveTestMethodAnalyzerTests.cs | 14 +++--- 16 files changed, 113 insertions(+), 12 deletions(-) diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx index 163432b37b..2bc73fbc94 100644 --- a/src/Analyzers/MSTest.Analyzers/Resources.resx +++ b/src/Analyzers/MSTest.Analyzers/Resources.resx @@ -337,6 +337,9 @@ Common scenarios where this rule triggers: Test class '{0}' does not contain any test method (method marked with '[TestMethod]'). Add a test method, or remove '[TestClass]' if this is a base class or not intended to be a test class. + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class should have test method diff --git a/src/Analyzers/MSTest.Analyzers/TestClassShouldHaveTestMethodAnalyzer.cs b/src/Analyzers/MSTest.Analyzers/TestClassShouldHaveTestMethodAnalyzer.cs index 1df1dbb6c5..65259b7c0c 100644 --- a/src/Analyzers/MSTest.Analyzers/TestClassShouldHaveTestMethodAnalyzer.cs +++ b/src/Analyzers/MSTest.Analyzers/TestClassShouldHaveTestMethodAnalyzer.cs @@ -32,9 +32,13 @@ public sealed class TestClassShouldHaveTestMethodAnalyzer : DiagnosticAnalyzer DiagnosticSeverity.Info, isEnabledByDefault: true); + /// + public static readonly DiagnosticDescriptor TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes = TestClassShouldHaveTestMethodRule + .WithMessage(new LocalizableResourceString(nameof(Resources.TestClassShouldHaveTestMethodMessageFormat_BaseClassHasAssemblyAttributes), Resources.ResourceManager, typeof(Resources))); + /// public override ImmutableArray SupportedDiagnostics { get; } - = ImmutableArray.Create(TestClassShouldHaveTestMethodRule); + = ImmutableArray.Create(TestClassShouldHaveTestMethodRule, TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes); /// public override void Initialize(AnalysisContext context) @@ -78,10 +82,13 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbo return; } - bool hasAssemblyAttribute = false; + bool hasAssemblyAttributeInCurrentClass = false; + bool hasAssemblyAttributeInBaseClass = false; + INamedTypeSymbol? baseClassWithAssemblyAttribute = null; bool hasTestMethod = false; INamedTypeSymbol? currentType = classSymbol; + bool isCurrentClass = true; do { foreach (ISymbol classMember in currentType.GetMembers()) @@ -98,18 +105,44 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbo || SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, globalTestInitializeAttributeSymbol) || SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, globalTestCleanupAttributeSymbol)) { - hasAssemblyAttribute = true; + if (isCurrentClass) + { + hasAssemblyAttributeInCurrentClass = true; + } + else + { + hasAssemblyAttributeInBaseClass = true; + baseClassWithAssemblyAttribute ??= currentType; + } } } } currentType = currentType.BaseType; + isCurrentClass = false; } while (currentType is not null); - if (!hasTestMethod && (!classSymbol.IsStatic || (classSymbol.IsStatic && !hasAssemblyAttribute))) + if (hasTestMethod) + { + return; + } + + // Static class with assembly attributes in the current class is valid + if (classSymbol.IsStatic && hasAssemblyAttributeInCurrentClass) + { + return; + } + + // Non-static class that inherits assembly attributes from base class - suggest making it static + if (!classSymbol.IsStatic && hasAssemblyAttributeInBaseClass && baseClassWithAssemblyAttribute is not null) { - context.ReportDiagnostic(classSymbol.CreateDiagnostic(TestClassShouldHaveTestMethodRule, classSymbol.Name)); + context.ReportDiagnostic(classSymbol.CreateDiagnostic(TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes, classSymbol.Name, baseClassWithAssemblyAttribute.Name)); + + return; } + + // All other cases: class without test methods + context.ReportDiagnostic(classSymbol.CreateDiagnostic(TestClassShouldHaveTestMethodRule, classSymbol.Name)); } } diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf index 4020a98b72..98a9f5c5b9 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf @@ -642,6 +642,11 @@ Typ deklarující tyto metody by měl také respektovat následující pravidla: Testovací třída {0} by měla být platná. + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid Vlastnost TestContext by měla být platná. diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf index dbbcb8c70a..2ec910210f 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf @@ -643,6 +643,11 @@ Der Typ, der diese Methoden deklariert, sollte auch die folgenden Regeln beachte Die Testklasse „{0}“ muss gültig sein + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid Die Eigenschaft „TestContext“ muss gültig sein diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf index c8b02ddf79..3a5bdba127 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf @@ -642,6 +642,11 @@ El tipo que declara estos métodos también debe respetar las reglas siguientes: La clase de prueba '{0}' debe ser válida + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid La propiedad 'TestContext' debe ser válida diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf index 197c564ca8..bd76344c0c 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf @@ -642,6 +642,11 @@ Le type déclarant ces méthodes doit également respecter les règles suivantes La classe de test « {0} » doit être valide + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid La propriété « TestContext » doit être valide diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf index f2928367ef..62590f7a38 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf @@ -642,6 +642,11 @@ Anche il tipo che dichiara questi metodi deve rispettare le regole seguenti: La classe di test '{0}' deve essere valida + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid La proprietà 'TestContext' deve essere valida diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf index 5e5c8b6bc2..8291f56c47 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf @@ -642,6 +642,11 @@ The type declaring these methods should also respect the following rules: テスト クラス '{0}' は有効である必要があります + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid プロパティ 'TestContext' は有効である必要があります diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf index 921b7b9cf4..78ae243128 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf @@ -642,6 +642,11 @@ The type declaring these methods should also respect the following rules: 테스트 클래스 '{0}'은(는) 유효해야 합니다. + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid 'TestContext' 속성은 유효해야 합니다. diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf index 335a149c02..08ebdcd0bb 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf @@ -642,6 +642,11 @@ Typ deklarujący te metody powinien również przestrzegać następujących regu Klasa testowa „{0}” powinna być prawidłowa + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid Właściwość „TestContext” powinna być prawidłowa diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf index a39a4cbfda..497b3131b0 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf @@ -642,6 +642,11 @@ O tipo que declara esses métodos também deve respeitar as seguintes regras: A classe de teste ''{0}'' deve ser válida + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid A propriedade ''TestContext'' deve ser válida diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf index 177f711e4a..c0af04ecf8 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf @@ -648,6 +648,11 @@ The type declaring these methods should also respect the following rules: Тестовый класс "{0}" должен быть допустимым + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid Свойство "TestContext" должно быть допустимым diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf index 00ca4dff79..443efafab4 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf @@ -642,6 +642,11 @@ Bu metotları bildiren türün ayrıca aşağıdaki kurallara uyması gerekir: '{0}' test sınıfı geçerli olmalıdır + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid 'TestContext' özelliği geçerli olmalıdır diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf index 7943c58b96..1fec856533 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf @@ -642,6 +642,11 @@ The type declaring these methods should also respect the following rules: 测试类“{0}”应该有效 + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid 属性 "TestContext" 应该有效 diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf index 70cef89bf9..7346c11fd7 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf @@ -642,6 +642,11 @@ The type declaring these methods should also respect the following rules: 測試類別 '{0}' 應為有效 + + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + Test class '{0}' does not contain any test method (method marked with '[TestMethod]'), but base class '{1}' contains assembly-level attributes. Make the class 'static' if it is only intended to contain assembly-level initialization or cleanup methods, or add a test method. + + Property 'TestContext' should be valid 屬性 'TestContext' 應為有效 diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs index e92555de5b..8c7b25cc75 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs @@ -201,7 +201,7 @@ public void TestMethod1UsingName() { } public class BaseClass : BaseBase { } - + [TestClass] public class Derived : BaseClass { @@ -219,7 +219,7 @@ public async Task WhenTestClassWithoutAssemblyAttributesAndTestMethod_InheritsFr public class BaseClass { } - + [TestClass] public class {|#0:Derived|} : BaseClass { @@ -245,7 +245,7 @@ public static void AssInit(TestContext testContext) { } } - + [TestClass] public class {|#0:Derived|} : BaseClass { @@ -253,9 +253,9 @@ public class {|#0:Derived|} : BaseClass """; await VerifyCS.VerifyAnalyzerAsync( code, - VerifyCS.Diagnostic(TestClassShouldHaveTestMethodAnalyzer.TestClassShouldHaveTestMethodRule) + VerifyCS.Diagnostic(TestClassShouldHaveTestMethodAnalyzer.TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes) .WithLocation(0) - .WithArguments("Derived")); + .WithArguments("Derived", "BaseClass")); } [TestMethod] @@ -283,9 +283,9 @@ public class {|#0:Derived|} : BaseClass """; await VerifyCS.VerifyAnalyzerAsync( code, - VerifyCS.Diagnostic(TestClassShouldHaveTestMethodAnalyzer.TestClassShouldHaveTestMethodRule) + VerifyCS.Diagnostic(TestClassShouldHaveTestMethodAnalyzer.TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes) .WithLocation(0) - .WithArguments("Derived")); + .WithArguments("Derived", "BaseBase")); } [TestMethod] From e356ac04fa8e437943f67936f6933627111b35f2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:58:35 +0000 Subject: [PATCH 3/4] Initial plan From 38168bf562e4bcc7810daaca74c2c26f3a3c4ea5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 16:01:39 +0000 Subject: [PATCH 4/4] Rename field to remove underscore per naming conventions Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../TestClassShouldHaveTestMethodAnalyzer.cs | 6 +++--- .../TestClassShouldHaveTestMethodAnalyzerTests.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Analyzers/MSTest.Analyzers/TestClassShouldHaveTestMethodAnalyzer.cs b/src/Analyzers/MSTest.Analyzers/TestClassShouldHaveTestMethodAnalyzer.cs index 65259b7c0c..637d1ee13e 100644 --- a/src/Analyzers/MSTest.Analyzers/TestClassShouldHaveTestMethodAnalyzer.cs +++ b/src/Analyzers/MSTest.Analyzers/TestClassShouldHaveTestMethodAnalyzer.cs @@ -33,12 +33,12 @@ public sealed class TestClassShouldHaveTestMethodAnalyzer : DiagnosticAnalyzer isEnabledByDefault: true); /// - public static readonly DiagnosticDescriptor TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes = TestClassShouldHaveTestMethodRule + public static readonly DiagnosticDescriptor TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes = TestClassShouldHaveTestMethodRule .WithMessage(new LocalizableResourceString(nameof(Resources.TestClassShouldHaveTestMethodMessageFormat_BaseClassHasAssemblyAttributes), Resources.ResourceManager, typeof(Resources))); /// public override ImmutableArray SupportedDiagnostics { get; } - = ImmutableArray.Create(TestClassShouldHaveTestMethodRule, TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes); + = ImmutableArray.Create(TestClassShouldHaveTestMethodRule, TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes); /// public override void Initialize(AnalysisContext context) @@ -137,7 +137,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbo // Non-static class that inherits assembly attributes from base class - suggest making it static if (!classSymbol.IsStatic && hasAssemblyAttributeInBaseClass && baseClassWithAssemblyAttribute is not null) { - context.ReportDiagnostic(classSymbol.CreateDiagnostic(TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes, classSymbol.Name, baseClassWithAssemblyAttribute.Name)); + context.ReportDiagnostic(classSymbol.CreateDiagnostic(TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes, classSymbol.Name, baseClassWithAssemblyAttribute.Name)); return; } diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs index 8c7b25cc75..bc485b4094 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs @@ -253,7 +253,7 @@ public class {|#0:Derived|} : BaseClass """; await VerifyCS.VerifyAnalyzerAsync( code, - VerifyCS.Diagnostic(TestClassShouldHaveTestMethodAnalyzer.TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes) + VerifyCS.Diagnostic(TestClassShouldHaveTestMethodAnalyzer.TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes) .WithLocation(0) .WithArguments("Derived", "BaseClass")); } @@ -283,7 +283,7 @@ public class {|#0:Derived|} : BaseClass """; await VerifyCS.VerifyAnalyzerAsync( code, - VerifyCS.Diagnostic(TestClassShouldHaveTestMethodAnalyzer.TestClassShouldHaveTestMethodRule_BaseClassHasAssemblyAttributes) + VerifyCS.Diagnostic(TestClassShouldHaveTestMethodAnalyzer.TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes) .WithLocation(0) .WithArguments("Derived", "BaseBase")); }