MSTEST0019: Prefer TestInitialize methods over constructors
Property | Value |
---|---|
Rule ID | MSTEST0019 |
Title | Prefer TestInitialize methods over constructors |
Category | Design |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default | No |
Default severity | Info |
Introduced in version | 3.4.0 |
Cause
This rule raises a diagnostic when there is a parameterless explicit constructor declared on a test class (class marked with [TestClass]
).
Rule description
Use this rule to enforce using [TestInitialize]
for both synchronous and asynchronous test initialization. Asynchronous (async/await) test intialization requires the use of [TestInitialize]
methods, because the resulting Task
needs to be awaited.
How to fix violations
Replace the constructor call with a [TestInitialize]
method.
When to suppress warnings
You usually don't want to suppress warnings from this rule if you decided to opt-in for it.
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