Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 1.83 KB

File metadata and controls

60 lines (44 loc) · 1.83 KB

PH2019: Avoid TestCleanup

Property Value
Package Philips.CodeAnalysis.MsTestAnalyzers
Diagnostic ID PH2019
Category MsTest
Analyzer AvoidAttributeAnalyzer
CodeFix No
Severity Error
Enabled By Default Yes

Introduction

The order that TestCleanup methods execute is not deterministic and can create unexpected test results. Moreover, it circumvents TestTimeouts.

How to solve

Keep your test architecture simple. Remove the method. Rely on standard coding techniques to call the method at the beginning of your test.

Example

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 Equivalent

Microsoft's official MSTest analyzers provide equivalent functionality:

Microsoft Rule Description
MSTEST0009 TestCleanup should be valid

Migration

Consider migrating to Microsoft's official MSTest analyzers which provide equivalent or better functionality with official support.

Configuration

This analyzer does not offer any special configuration. The general ways of suppressing diagnostics apply.