नोट
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप साइन इन करने या निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
| Property | Value |
|---|---|
| Rule ID | MSTEST0012 |
| Title | AssemblyInitialize method should have valid layout |
| Category | Usage |
| Fix is breaking or non-breaking | Non-breaking |
| Enabled by default | Yes |
| Default severity | Warning |
| Introduced in version | 3.3.0 |
| Is there a code fix | Yes |
Cause
A method marked with [AssemblyInitialize] should have valid layout.
Rule description
Methods marked with [AssemblyInitialize] should follow the following layout to be valid:
- it should be
public - it should be
static - it should not be
async void - it should not be a special method (finalizer, operator...).
- it should not be generic
- it should not be abstract
- it should take one parameter of type
TestContext - return type should be
void,TaskorValueTask
The type declaring these methods should also respect the following rules:
- The type should be a class.
- The class should be public or internal (if the test project is using the [DiscoverInternals] attribute).
- The class should be marked with [TestClass] (or a derived attribute)
- the class should not be generic
How to fix violations
Ensure that the method matches the layout described above.
When to suppress warnings
Do not suppress a warning from this rule. If you ignore this rule, flagged instances will be either skipped or result in runtime error.
Suppress a warning
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable MSTEST0012
// The code that's violating the rule is on this line.
#pragma warning restore MSTEST0012
To disable the rule for a file, folder, or project, set its severity to none in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.MSTEST0012.severity = none
For more information, see How to suppress code analysis warnings.