From 2319104f38f85ad065762ce938f0604f7b3562c7 Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Sat, 6 Jul 2024 12:21:50 +0200 Subject: [PATCH] Add analyzer for TestCase and missing Category --- .../NUnit/NUnitTestMissingCategoryAnalyzer.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/TestUtils/src/UITest.Analyzers/NUnit/NUnitTestMissingCategoryAnalyzer.cs b/src/TestUtils/src/UITest.Analyzers/NUnit/NUnitTestMissingCategoryAnalyzer.cs index 780d996ec4c7..163eb478b366 100644 --- a/src/TestUtils/src/UITest.Analyzers/NUnit/NUnitTestMissingCategoryAnalyzer.cs +++ b/src/TestUtils/src/UITest.Analyzers/NUnit/NUnitTestMissingCategoryAnalyzer.cs @@ -39,8 +39,9 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context) { var methodSymbol = (IMethodSymbol)context.Symbol; - // Check if the method has the [Test] attribute. - var hasTestAttribute = methodSymbol.GetAttributes().Any(attr => attr?.AttributeClass?.Name == "TestAttribute"); + // Check if the method has the [Test] or [TestCase] attribute. + var hasTestAttribute = methodSymbol.GetAttributes().Any(attr => attr?.AttributeClass?.Name == "TestAttribute" + || attr?.AttributeClass?.Name == "TestCaseAttribute"); // Check if the method has the [Category] attribute. var hasCategoryAttribute = methodSymbol.GetAttributes().Any(attr => attr?.AttributeClass?.Name == "CategoryAttribute"); @@ -51,7 +52,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context) hasCategoryAttribute = containingClass.GetAttributes().Any(attr => attr?.AttributeClass?.Name == "CategoryAttribute"); } - // If it has [Test] but not [Category], report a diagnostic. + // If it has [Test] or [TestCase] but not [Category], report a diagnostic. if (hasTestAttribute && !hasCategoryAttribute) { var diagnostic = Diagnostic.Create(Rule, methodSymbol.Locations[0], methodSymbol.Name);