diff --git a/src/Analyzers/MSTest.Analyzers/AnalyzerReleases.Unshipped.md b/src/Analyzers/MSTest.Analyzers/AnalyzerReleases.Unshipped.md
index 6eea619003..e1a0736a05 100644
--- a/src/Analyzers/MSTest.Analyzers/AnalyzerReleases.Unshipped.md
+++ b/src/Analyzers/MSTest.Analyzers/AnalyzerReleases.Unshipped.md
@@ -1,2 +1,7 @@
; Unshipped analyzer release
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
+### New Rules
+
+Rule ID | Category | Severity | Notes
+--------|----------|----------|-------
+MSTEST0011 | Usage | Info | TestPropertyAttributeOnTestMethodAnalyzer
\ No newline at end of file
diff --git a/src/Analyzers/MSTest.Analyzers/Helpers/DiagnosticIds.cs b/src/Analyzers/MSTest.Analyzers/Helpers/DiagnosticIds.cs
index 66a93c0709..f10f47760b 100644
--- a/src/Analyzers/MSTest.Analyzers/Helpers/DiagnosticIds.cs
+++ b/src/Analyzers/MSTest.Analyzers/Helpers/DiagnosticIds.cs
@@ -11,4 +11,5 @@ internal static class DiagnosticIds
public const string PublicTypeShouldBeTestClassRuleId = "MSTEST0004";
public const string TestContextShouldBeValidRuleId = "MSTEST0005";
public const string AvoidExpectedExceptionAttributeRuleId = "MSTEST0006";
+ public const string TestPropertyAttributeOnTestMethodRuleId = "MSTEST0011";
}
diff --git a/src/Analyzers/MSTest.Analyzers/Helpers/WellKnownTypeNames.cs b/src/Analyzers/MSTest.Analyzers/Helpers/WellKnownTypeNames.cs
index fd73b435b5..6aff2a5b4d 100644
--- a/src/Analyzers/MSTest.Analyzers/Helpers/WellKnownTypeNames.cs
+++ b/src/Analyzers/MSTest.Analyzers/Helpers/WellKnownTypeNames.cs
@@ -13,6 +13,7 @@ internal static class WellKnownTypeNames
public const string MicrosoftVisualStudioTestToolsUnitTestingTestContext = "Microsoft.VisualStudio.TestTools.UnitTesting.TestContext";
public const string MicrosoftVisualStudioTestToolsUnitTestingTestMethodAttribute = "Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute";
public const string MicrosoftVisualStudioTestToolsUnitTestingExpectedExceptionAttribute = "Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionAttribute";
+ public const string MicrosoftVisualStudioTestToolsUnitTestingTestPropertyAttribute = "Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute";
public const string SystemThreadingTasksTask = "System.Threading.Tasks.Task";
public const string SystemThreadingTasksTask1 = "System.Threading.Tasks.Task`1";
diff --git a/src/Analyzers/MSTest.Analyzers/Resources.Designer.cs b/src/Analyzers/MSTest.Analyzers/Resources.Designer.cs
index d6e2f794da..44f73a41d6 100644
--- a/src/Analyzers/MSTest.Analyzers/Resources.Designer.cs
+++ b/src/Analyzers/MSTest.Analyzers/Resources.Designer.cs
@@ -335,6 +335,33 @@ internal static string TestMethodShouldBeValidTitle {
}
}
+ ///
+ /// Looks up a localized string similar to [TestProperty] can only be set on methods marked with [TestMethod]..
+ ///
+ internal static string TestPropertyAttributeOnTestMethodAnalyzerDescription {
+ get {
+ return ResourceManager.GetString("TestPropertyAttributeOnTestMethodAnalyzerDescription", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to [TestProperty] can only be set on methods marked with [TestMethod].
+ ///
+ internal static string TestPropertyAttributeOnTestMethodAnalyzerMessageFormat {
+ get {
+ return ResourceManager.GetString("TestPropertyAttributeOnTestMethodAnalyzerMessageFormat", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to TestPropertyAttribute should be set on TestMethod.
+ ///
+ internal static string TestPropertyAttributeOnTestMethodAnalyzerTitle {
+ get {
+ return ResourceManager.GetString("TestPropertyAttributeOnTestMethodAnalyzerTitle", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'..
///
diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx
index 03b7a074ed..cb3c81ab23 100644
--- a/src/Analyzers/MSTest.Analyzers/Resources.resx
+++ b/src/Analyzers/MSTest.Analyzers/Resources.resx
@@ -218,6 +218,15 @@
Test methods should have valid layout
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+ TestPropertyAttribute should be set on TestMethod
+
By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.
diff --git a/src/Analyzers/MSTest.Analyzers/TestPropertyAttributeOnTestMethodAnalyzer.cs b/src/Analyzers/MSTest.Analyzers/TestPropertyAttributeOnTestMethodAnalyzer.cs
new file mode 100644
index 0000000000..bb8ffcb050
--- /dev/null
+++ b/src/Analyzers/MSTest.Analyzers/TestPropertyAttributeOnTestMethodAnalyzer.cs
@@ -0,0 +1,77 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System.Collections.Immutable;
+
+using Analyzer.Utilities.Extensions;
+
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.Diagnostics;
+
+using MSTest.Analyzers.Helpers;
+
+namespace MSTest.Analyzers;
+
+[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
+public sealed class TestPropertyAttributeOnTestMethodAnalyzer : DiagnosticAnalyzer
+{
+ private static readonly LocalizableResourceString Title = new(nameof(Resources.TestPropertyAttributeOnTestMethodAnalyzerTitle), Resources.ResourceManager, typeof(Resources));
+ private static readonly LocalizableResourceString Description = new(nameof(Resources.TestPropertyAttributeOnTestMethodAnalyzerDescription), Resources.ResourceManager, typeof(Resources));
+ private static readonly LocalizableResourceString MessageFormat = new(nameof(Resources.TestPropertyAttributeOnTestMethodAnalyzerMessageFormat), Resources.ResourceManager, typeof(Resources));
+
+ internal static readonly DiagnosticDescriptor Rule = DiagnosticDescriptorHelper.Create(
+ DiagnosticIds.TestPropertyAttributeOnTestMethodRuleId,
+ Title,
+ MessageFormat,
+ Description,
+ Category.Usage,
+ DiagnosticSeverity.Info,
+ isEnabledByDefault: true);
+
+ public override ImmutableArray SupportedDiagnostics { get; }
+ = ImmutableArray.Create(Rule);
+
+ public override void Initialize(AnalysisContext context)
+ {
+ context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
+ context.EnableConcurrentExecution();
+
+ context.RegisterCompilationStartAction(context =>
+ {
+ if (context.Compilation.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftVisualStudioTestToolsUnitTestingTestMethodAttribute, out var testMethodAttributeSymbol)
+ && context.Compilation.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftVisualStudioTestToolsUnitTestingTestPropertyAttribute, out var testPropertyAttributeSymbol))
+ {
+ context.RegisterSymbolAction(context => AnalyzeSymbol(context, testMethodAttributeSymbol, testPropertyAttributeSymbol), SymbolKind.Method);
+ }
+ });
+ }
+
+ private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbol testMethodAttributeSymbol,
+ INamedTypeSymbol testPropertyAttributeSymbol)
+ {
+ IMethodSymbol methodSymbol = (IMethodSymbol)context.Symbol;
+
+ AttributeData? testPropertyAttribute = null;
+ bool hasTestMethodAttribute = false;
+ foreach (var methodAttribute in methodSymbol.GetAttributes())
+ {
+ if (methodAttribute.AttributeClass.Inherits(testMethodAttributeSymbol))
+ {
+ hasTestMethodAttribute = true;
+ }
+
+ if (SymbolEqualityComparer.Default.Equals(methodAttribute?.AttributeClass, testPropertyAttributeSymbol))
+ {
+ testPropertyAttribute = methodAttribute;
+ }
+ }
+
+ if (testPropertyAttribute is not null && !hasTestMethodAttribute)
+ {
+ if (testPropertyAttribute.ApplicationSyntaxReference?.GetSyntax() is { } syntax)
+ {
+ context.ReportDiagnostic(syntax.CreateDiagnostic(Rule));
+ }
+ }
+ }
+}
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
index abe314495e..08f475c9b7 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
@@ -175,6 +175,21 @@
Testovací metody by měly mít platné rozložení.
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.Ve výchozím nastavení spouští MSTest testy v rámci stejného sestavení sekvenčně, což může vést k závažným omezením výkonu. Doporučuje se povolit atribut sestavení [Parallelize] k paralelnímu spouštění testů nebo explicitně použít atribut [DoNotParallelize] na úrovni sestavení, pokud je známo, že sestavení není paralelizovatelné.
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf
index d21f0011d7..731b341ccb 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf
@@ -175,6 +175,21 @@
Testmethoden müssen über ein gültiges Layout verfügen.
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.Standardmäßig führt MSTest Tests in derselben Assembly sequentiell aus, was zu erheblichen Leistungseinschränkungen führen kann. Es wird empfohlen, das Assembly-Attribut "[Parallelize]" zu aktivieren, um Tests parallel auszuführen, oder, wenn bekannt ist, dass die Assembly nicht parallelisierbar ist, explizit das Assembly-Attribut "[DoNotParallelize]" zu verwenden.
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf
index d8123b9c11..2ddaac5b5d 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf
@@ -175,6 +175,21 @@
Los métodos de prueba deben tener un diseño válido
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.De forma predeterminada, MSTest ejecuta pruebas en el mismo ensamblado secuencialmente, lo que puede provocar limitaciones de rendimiento graves. Se recomienda habilitar el atributo de ensamblado ''[Parallelize]'' o, si se sabe que el ensamblado no se puede paralelizar, usar explícitamente el atributo de nivel de ensamblado ''[DoNotParallelize]''.
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf
index 68d451df4a..8547d063a6 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf
@@ -175,6 +175,21 @@
Les méthodes de test doivent avoir une disposition valide
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.Par défaut, MSTest exécute des tests dans la même assembly de façon séquentielle, ce qui peut entraîner de graves limitations de performances. Il est recommandé d’activer l’attribut d’assemblée « [Parallelize] » pour exécuter des tests en parallèle ou, si l’assemblée est connu pour ne pas être parallélisable, d’utiliser explicitement l’attribut de niveau assemblée « [DoNotParallelize] ».
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf
index a04e16c25c..f510267aae 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf
@@ -175,6 +175,21 @@
I metodi di test dovrebbero avere un layout valido
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.Per impostazione predefinita, MSTest esegue i test in sequenza nello stesso assemby, il che può causare gravi limitazioni delle prestazioni. È consigliabile abilitare l'attributo di assembly '[Parallelize]' per eseguire i test in parallelo, o, se l'assembly non è parallelizzabile, usare in modo esplicito l'attributo a livello di assembly '[DoNotParallelize]'.
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf
index 6287dbc905..dcdc40a3c6 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf
@@ -176,6 +176,21 @@
テスト メソッドには有効なレイアウトが必要です
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.既定では、MSTest は同じアセンブリ内でテストを順番に実行するため、重大なパフォーマンス制限が生じる可能性があります。アセンブリ属性 '[Parallelize]' を有効にして並列でテストを実行するか、アセンブリが並列化できないことがわかっている場合は、アセンブリ レベル属性 '[DoNotParallelize]' を明示的に使用することをお勧めします。
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf
index 0164767723..321e23f5eb 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf
@@ -176,6 +176,21 @@
테스트 메서드에는 유효한 레이아웃이 있어야 합니다.
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.기본적으로 MSTest는 동일한 어셈블리 내에서 테스트를 순차적으로 실행하므로 심각한 성능 제한이 발생할 수 있습니다. 어셈블리 특성 '[Parallelize]'가 병렬로 테스트를 실행하도록 설정하거나 어셈블리가 병렬화할 수 없는 것으로 알려진 경우 어셈블리 수준 특성 '[DoNotParallelize]'을(를) 명시적으로 사용하는 것이 좋습니다.
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf
index 17016cff3c..1803de03df 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf
@@ -175,6 +175,21 @@
Metody testowe powinny mieć prawidłowy układ
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.Domyślnie platforma MSTest uruchamia testy w ramach tego samego zestawu sekwencyjnie, co może prowadzić do poważnego ograniczenia wydajności. Zaleca się włączenie atrybutu zestawu „[Parallelize]”, aby uruchamiać testy równolegle, lub jeśli zestaw na to nie pozwala — użycie jawnie atrybutu poziomu zestawu „[DoNotParallelize]”.
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf
index 398ad00cb1..d9cc0f7636 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf
@@ -175,6 +175,21 @@
Os métodos de teste devem ter um layout válido
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.Por padrão, o MSTest executa testes no mesmo assembly sequencialmente, o que pode levar a limitações graves de desempenho. É recomendável habilitar o atributo de assembly ''[Parallelize]'' para executar testes em paralelo ou se o assembly for conhecido por não ser paralelizável, para usar explicitamente o atributo de nível de assembly ''[DoNotParallelize]''.
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf
index f085d9ef58..6b3a62bf68 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf
@@ -175,6 +175,21 @@
Методы теста должны использовать допустимую структуру
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.По умолчанию MSTest выполняет тесты в одной сборке последовательно, что может привести к серьезному ограничению производительности. Рекомендуется включить атрибут сборки "[Parallelize]", чтобы выполнять тесты параллельно, или явно использовать атрибут уровня сборки "[DoNotParallelize]", если известно, что сборка не поддерживает параллелизацию.
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf
index 0001d7c3af..1d07ed8dbe 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf
@@ -177,6 +177,21 @@
Test yöntemleri geçerli bir düzene sahip olmalıdır
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.Varsayılan olarak, MSTest hizmeti testleri aynı derleme içinde sırayla çalıştırır ve bu durum ciddi performans sınırlamalarına yol açabilir. Testleri paralel yürütmek için '[Parallelize]' derleme özniteliğini etkinleştirmeniz önerilir veya derlemenin paralelleştirilebilir olduğu biliniyorsa, doğrudan '[DoNotParallelize]' derleme düzeyi özniteliğini kullanmanız önerilir.
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf
index 662f59945a..55f9c51d5a 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf
@@ -175,6 +175,21 @@
测试方法应具有有效的布局
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.默认情况下,MSTest 将按顺序在同一程序集中运行测试,这可能会导致严重的性能限制。建议启用程序集属性“[Parallelize]”以并行运行测试,或者如果已知程序集不可并行,则显式使用程序集级别属性“DoNotParallelize”。
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf
index f303a39ade..950d17aa31 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf
@@ -175,6 +175,21 @@
測試方法應具備有效的配置
+
+ [TestProperty] can only be set on methods marked with [TestMethod].
+ [TestProperty] can only be set on methods marked with [TestMethod].
+
+
+
+ [TestProperty] can only be set on methods marked with [TestMethod]
+ [TestProperty] can only be set on methods marked with [TestMethod]
+
+
+
+ TestPropertyAttribute should be set on TestMethod
+ TestPropertyAttribute should be set on TestMethod
+
+ By default, MSTest runs tests within the same assembly sequentially, which can lead to severe performance limitations. It is recommended to enable assembly attribute '[Parallelize]' to run tests in parallel, or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute '[DoNotParallelize]'.根據預設,MSTest 會依順序執行在相同組件內的測試,這可能會導致嚴重的效能限制。建議啟用組件屬性 '[Parallelize]' 來平行執行測試,或者如果已知組件無法平行處理,則明確使用組件層級的屬性 '[DoNotParallelize]'。
diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestPropertyAttributeOnTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestPropertyAttributeOnTestMethodAnalyzerTests.cs
new file mode 100644
index 0000000000..e8375f65ea
--- /dev/null
+++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestPropertyAttributeOnTestMethodAnalyzerTests.cs
@@ -0,0 +1,79 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using Microsoft.Testing.Framework;
+using Microsoft.Testing.TestInfrastructure;
+
+using VerifyCS = MSTest.Analyzers.Test.CSharpCodeFixVerifier<
+ MSTest.Analyzers.TestPropertyAttributeOnTestMethodAnalyzer,
+ Microsoft.CodeAnalysis.Testing.EmptyCodeFixProvider>;
+
+namespace MSTest.Analyzers.UnitTests;
+
+[TestGroup]
+public sealed class TestPropertyAttributeOnTestMethodAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext)
+{
+ public async Task WhenMethodIsMarkedWithTestMethodAndTestPropertyAttributes_NoDiagnostic()
+ {
+ var code = """
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class MyTestClass
+ {
+ [TestMethod]
+ [TestProperty("name", "value")]
+ public void TestMethod()
+ {
+ }
+ }
+ """
+ ;
+
+ await VerifyCS.VerifyAnalyzerAsync(code);
+ }
+
+ public async Task WhenMethodIsMarkedWithTestPropertyAttributeButNotWithTestMethod_Diagnostic()
+ {
+ var code = """
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class MyTestClass
+ {
+ [{|#0:TestProperty("name", "value")|}]
+ public void TestMethod()
+ {
+ }
+ }
+ """
+ ;
+ await VerifyCS.VerifyAnalyzerAsync(code, VerifyCS.Diagnostic().WithLocation(0));
+ }
+
+ public async Task WhenMethodIsMarkedWithTestPropertyAttributeAndCustomTestMethod_NoDiagnostic()
+ {
+ var code = """
+ using System;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class MyTestClass
+ {
+ [TestProperty("name", "value")]
+ [MyCustomTestMethod]
+ public void TestMethod()
+ {
+ }
+ }
+
+ [AttributeUsage(AttributeTargets.Method)]
+ public class MyCustomTestMethodAttribute : TestMethodAttribute
+ {
+ }
+ """
+ ;
+
+ await VerifyCS.VerifyAnalyzerAsync(code);
+ }
+}