diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx
index 843c399635..2bc73fbc94 100644
--- a/src/Analyzers/MSTest.Analyzers/Resources.resx
+++ b/src/Analyzers/MSTest.Analyzers/Resources.resx
@@ -323,10 +323,22 @@ 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 '{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..637d1ee13e 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 TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes = TestClassShouldHaveTestMethodRule
+ .WithMessage(new LocalizableResourceString(nameof(Resources.TestClassShouldHaveTestMethodMessageFormat_BaseClassHasAssemblyAttributes), Resources.ResourceManager, typeof(Resources)));
+
///
public override ImmutableArray SupportedDiagnostics { get; }
- = ImmutableArray.Create(TestClassShouldHaveTestMethodRule);
+ = ImmutableArray.Create(TestClassShouldHaveTestMethodRule, TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes);
///
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(TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes, 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 d040ccf7c1..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 validVlastnost TestContext by měla být platná.
@@ -704,13 +709,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..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 validDie Eigenschaft „TestContext“ muss gültig sein
@@ -705,13 +710,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..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 validLa propiedad 'TestContext' debe ser válida
@@ -704,13 +709,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..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 validLa propriété « TestContext » doit être valide
@@ -704,13 +709,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..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 validLa proprietà 'TestContext' deve essere valida
@@ -704,13 +709,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..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' は有効である必要があります
@@ -704,13 +709,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..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' 속성은 유효해야 합니다.
@@ -704,13 +709,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..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 validWłaściwość „TestContext” powinna być prawidłowa
@@ -704,13 +709,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..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 validA propriedade ''TestContext'' deve ser válida
@@ -704,13 +709,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..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" должно быть допустимым
@@ -710,13 +715,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..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
@@ -705,13 +710,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..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" 应该有效
@@ -704,13 +709,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..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' 應為有效
@@ -704,13 +709,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]'標示。
diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs
index e92555de5b..bc485b4094 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.TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes)
.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.TestClassShouldHaveTestMethodRuleBaseClassHasAssemblyAttributes)
.WithLocation(0)
- .WithArguments("Derived"));
+ .WithArguments("Derived", "BaseBase"));
}
[TestMethod]