MSTEST0010: ClassInitialize method should have valid layout
Property | Value |
---|---|
Rule ID | MSTEST0010 |
Title | ClassInitialize 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 |
Cause
A method marked with [ClassInitialize]
should have valid layout.
Rule description
Methods marked with [ClassInitialize]
should follow the following layout to be valid:
- it can't be declared on a generic class without the
InheritanceBehavior
mode is set - 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 take one parameter of type
TestContext
- return type should be
void
,Task
orValueTask
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.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for