You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/testing/mstest-analyzers/mstest0056.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ A test method attribute uses a string constructor argument instead of the <xref:
33
33
34
34
## Rule description
35
35
36
-
When specifying a custom display name for a test method, you should use the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.DisplayName> property instead of passing a string as a constructor argument. This ensures consistent usage across the MSTest framework and improves code readability.
36
+
When specifying a custom display name for a test method, you should use the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.DisplayName> property instead of passing a string as a constructor argument. In MSTest 4.0 and later, the string constructor argument is used for source information (caller file path) rather than display name, which is a breaking change from MSTest 3.x. Using the `DisplayName` property ensures your code works correctly and avoids potential confusion.
37
37
38
38
```csharp
39
39
[TestClass]
@@ -65,7 +65,7 @@ public class TestClass
65
65
66
66
## When to suppress warnings
67
67
68
-
Do not suppress warnings from this rule. Using the `DisplayName` property is the correct and recommended way to specify custom display names for test methods.
68
+
Do not suppress warnings from this rule. Using the `DisplayName` property is the only way to specify custom display names for test methods. If your intent is to explicitly pass a value for the caller file path parameter instead of setting a display name, you can suppress this warning, but this is rarely needed.
Copy file name to clipboardExpand all lines: docs/core/testing/mstest-analyzers/mstest0057.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ A custom <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute>
33
33
34
34
## Rule description
35
35
36
-
When creating custom test method attributes that derive from <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute>, you should propagate source information using caller information attributes. This allows MSTest to correctly track the source file and line number for test methods, improving diagnostics and test result reporting.
36
+
When creating custom test method attributes that derive from <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute>, you should propagate source information using caller information attributes. This allows MSTest to correctly track the source file and line number for test methods, improving diagnostics, test result reporting, and Test Explorer behavior.
Copy file name to clipboardExpand all lines: docs/core/testing/mstest-analyzers/mstest0059.md
+30-3Lines changed: 30 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,12 +33,12 @@ An assembly contains both <xref:Microsoft.VisualStudio.TestTools.UnitTesting.Par
33
33
34
34
## Rule description
35
35
36
-
The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.ParallelizeAttribute> and <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DoNotParallelizeAttribute> attributes are mutually exclusive. Having both attributes in the same assembly creates conflicting configuration that can lead to unpredictable test execution behavior. You should choose one parallelization strategy for your test assembly.
36
+
The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.ParallelizeAttribute> and <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DoNotParallelizeAttribute> attributes are mutually exclusive at the assembly level. When both attributes are applied to the same assembly, tests run sequentially. This conflicting configuration indicates unclear intent and should be resolved by choosing one parallelization strategy for your test assembly.
@@ -62,6 +62,33 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
62
62
[assembly: DoNotParallelize]
63
63
```
64
64
65
+
If you want to enable parallelization at the assembly level but disable it for specific classes or methods, apply `Parallelize` at the assembly level and `DoNotParallelize` at the class or method level:
Copy file name to clipboardExpand all lines: docs/core/testing/mstest-analyzers/mstest0060.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,14 +33,14 @@ A test method has multiple <xref:Microsoft.VisualStudio.TestTools.UnitTesting.Te
33
33
34
34
## Rule description
35
35
36
-
A test method should have only one attribute that derives from <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute>. Having multiple test method attributes (such as `[TestMethod]` and `[DataTestMethod]`) on the same method can lead to unexpected behavior and test execution issues.
36
+
A test method should have only one attribute that derives from <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute>. Having multiple test method attributes (such as `[TestMethod]` and `[UITestMethod]`) on the same method causes only one attribute to be used (the first one returned by reflection), which can be confusing and lead to unintended test execution.
37
37
38
38
```csharp
39
39
[TestClass]
40
40
publicclassTestClass
41
41
{
42
42
[TestMethod]
43
-
[DataTestMethod] // Violation
43
+
[UITestMethod] // Violation
44
44
publicvoidTestMethod1()
45
45
{
46
46
// Test code
@@ -66,7 +66,7 @@ public class TestClass
66
66
67
67
## When to suppress warnings
68
68
69
-
Do not suppress warnings from this rule. Having multiple test method attributes creates ambiguous test configuration that should be resolved.
69
+
Do not suppress warnings from this rule. Having multiple test method attributes creates ambiguous test configuration where only one attribute is used, which can cause confusion about which test behavior is actually applied.
Copy file name to clipboardExpand all lines: docs/core/testing/mstest-analyzers/mstest0062.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ A test method has parameters marked with `out` or `ref` modifiers.
33
33
34
34
## Rule description
35
35
36
-
Test methods should not have `out` or `ref` parameters because these modifiers are incompatible with data-driven testing. Data sources provide values to test methods through standard parameter passing, and the `out` and `ref`modifiers create conflicts with this mechanism. Using regular parameters makes tests more maintainable and compatible with parameterized test features.
36
+
Test methods should not have `out` or `ref` parameters. MSTest is responsible for calling test methods, and it never reads the values that are passed by reference after the test method finishes. These modifiers are misleading because they suggest the test method returns values that will be used, but MSTest never uses them after the test completes.
37
37
38
38
```csharp
39
39
[TestClass]
@@ -56,7 +56,7 @@ Remove the `out` and `ref` modifiers from test method parameters.
You might suppress this warning if you have a specific advanced scenario that requires `out` or `ref` parameters. However, this is rare, and you should consider alternative test designs first.
117
+
Do not suppress warnings from this rule. There is no valid scenario where test methods should use `out` or `ref` parameters.
0 commit comments