diff --git a/docs/core/testing/mstest-analyzers/mstest0050.md b/docs/core/testing/mstest-analyzers/mstest0050.md new file mode 100644 index 0000000000000..ede9a976055a3 --- /dev/null +++ b/docs/core/testing/mstest-analyzers/mstest0050.md @@ -0,0 +1,43 @@ +--- +title: "MSTEST0050: Global test fixture should be valid" +description: "Learn about code analysis rule MSTEST0050: Global test fixture should be valid" +ms.date: 07/29/2025 +f1_keywords: +- MSTEST0050 +- GlobalTestFixtureShouldBeValidAnalyzer +helpviewer_keywords: +- GlobalTestFixtureShouldBeValidAnalyzer +- MSTEST0050 +author: Evangelink +ms.author: amauryleve +--- +# MSTEST0050: Global test fixture should be valid + +| Property | Value | +|-------------------------------------|------------------------------------------------------------------------------------------| +| **Rule ID** | MSTEST0050 | +| **Title** | Global test fixture should be valid | +| **Category** | Usage | +| **Fix is breaking or non-breaking** | Non-breaking | +| **Enabled by default** | Yes | +| **Default severity** | Error | +| **Introduced in version** | 3.10.0 | +| **Is there a code fix** | No | + +## Cause + +A global test fixture method (marked with `GlobalTestInitializeAttribute` or `GlobalTestCleanupAttribute`) doesn't follow the required layout or has invalid configuration. + +## Rule description + +Global test fixture methods must follow specific requirements to ensure proper test execution. This rule validates that methods marked with `GlobalTestInitializeAttribute` or `GlobalTestCleanupAttribute` adhere to the correct method signature and configuration rules. + +The method must be `public`, `static`, non-generic, have a single parameter of type `TestContext`, and return `void` or `Task`. In addition, the containing type must be `public`, `static`, non-generic, and be marked with `TestClassAttribute`. + +## How to fix violations + +Ensure that global test fixture methods follow the required layout. + +## When to suppress warnings + +Don't suppress warnings from this rule. Invalid global test fixture methods will not execute at run-time. diff --git a/docs/core/testing/mstest-analyzers/usage-rules.md b/docs/core/testing/mstest-analyzers/usage-rules.md index bb81c13759a17..081ae40c21f5e 100644 --- a/docs/core/testing/mstest-analyzers/usage-rules.md +++ b/docs/core/testing/mstest-analyzers/usage-rules.md @@ -43,3 +43,4 @@ Identifier | Name | Description [MSTEST0046](mstest0046.md) | StringAssertToAssertAnalyzer | A test method uses methods instead of equivalent methods. [MSTEST0048](mstest0048.md) | TestContextPropertyUsageAnalyzer | A fixture method (methods with , , , or ) accesses restricted properties. [MSTEST0049](mstest0049.md) | FlowTestContextCancellationTokenAnalyzer | A method call within a test context doesn't use the available from when the called method has a parameter or overload that accepts a . +[MSTEST0050](mstest0050.md) | GlobalTestFixtureShouldBeValidAnalyzer | A global test fixture method (marked with `GlobalTestInitializeAttribute` or `GlobalTestCleanupAttribute`) doesn't follow the required layout or has invalid configuration. diff --git a/docs/navigate/devops-testing/toc.yml b/docs/navigate/devops-testing/toc.yml index 37fff51e8423a..0221c6819b87b 100644 --- a/docs/navigate/devops-testing/toc.yml +++ b/docs/navigate/devops-testing/toc.yml @@ -225,6 +225,8 @@ items: href: ../../core/testing/mstest-analyzers/mstest0048.md - name: MSTEST0049 href: ../../core/testing/mstest-analyzers/mstest0049.md + - name: MSTEST0050 + href: ../../core/testing/mstest-analyzers/mstest0050.md - name: Test platforms items: - name: Microsoft.Testing.Platform