| Property | Value |
|---|---|
| Package | Philips.CodeAnalysis.MsTestAnalyzers |
| Diagnostic ID | PH2019 |
| Category | MsTest |
| Analyzer | AvoidAttributeAnalyzer |
| CodeFix | No |
| Severity | Error |
| Enabled By Default | Yes |
The order that TestCleanup methods execute is not deterministic and can create unexpected test results. Moreover, it circumvents TestTimeouts.
Keep your test architecture simple. Remove the method. Rely on standard coding techniques to call the method at the beginning of your test.
Code that triggers a diagnostic:
[TestCleanup()]
public void Cleanup()
{ }
[TestMethod]
public void BadTestMethod()
{
Assert.AreEqual(1, 1);
}Fix the above code as follows:
[TestMethod]
public void BadTestMethod()
{
Assert.AreEqual(1, 1);
Cleanup();
}Microsoft's official MSTest analyzers provide equivalent functionality:
| Microsoft Rule | Description |
|---|---|
| MSTEST0009 | TestCleanup should be valid |
Consider migrating to Microsoft's official MSTest analyzers which provide equivalent or better functionality with official support.
This analyzer does not offer any special configuration. The general ways of suppressing diagnostics apply.