MSTEST0020: Prefer constructors over TestInitialize methods
Property | Value |
---|---|
Rule ID | MSTEST0020 |
Title | Prefer constructors over TestInitialize methods |
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 void [TestInitialize]
method.
Rule description
It is usually better to rely on constructors for non-async initialization as you can then rely on readonly
and get better compiler feedback when developing your tests. This is especially true when dealing with nullable enabled contexts.
How to fix violations
Replace [TestInitialize]
returning void
by constructors.
When to suppress warnings
You usually don't want to suppress warnings from this rule if you decided to opt-in for it.
Samarbejd med os på GitHub
Kilden til dette indhold kan findes på GitHub, hvor du også kan oprette og gennemse problemer og pullanmodninger. Du kan få flere oplysninger i vores vejledning til bidragydere.
Feedback
https://aka.ms/ContentUserFeedback.
Kommer snart: I hele 2024 udfaser vi GitHub-problemer som feedbackmekanisme for indhold og erstatter det med et nyt feedbacksystem. Du kan få flere oplysninger under:Indsend og få vist feedback om