Skip to content

ClassCleanup is not executed when Ignore (Attribute) is applied to the first test method in a series of test methods in a test class #5062

Description

@minghan

Describe the bug

The ClassCleanup is not executed when Ignore (Attribute) is applied to the first test method in a series of test methods in a test class.

Steps To Reproduce

The following code reproduces the issue. You can set a breakpoint in ClassCleanup method and observe that it is not executed.

Note that the ClassCleanup method is executed if we move the [Ignore] attribute from TestMethod1 to TestMethod2 instead.

I am able to reproduce the bug with MSTest 3.8.0.

namespace UnitTestBugRepro
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class UnitTest1
    {
        [ClassInitialize()]
        public static void ClassInit(TestContext context)
        {
            Console.WriteLine("Class Init");
        }

        [ClassCleanup(ClassCleanupBehavior.EndOfClass)]
        public static void ClassCleanup()
        {
            Console.WriteLine("Class Cleanup");
        }

        [Ignore]
        [TestMethod]
        public void TestMethod1()
        {
            Console.WriteLine("TestMethod1");
        }

        [TestMethod]
        public void TestMethod2()
        {
            Console.WriteLine("TestMethod2");
        }
    }
}

Expected behavior

TestMethod1() is ignored and ClassCleanup() method is executed.

Actual behavior

TestMethod1() is ignored and ClassCleanup() method is not executed.

Metadata

Metadata

Labels

area/fixturesTest class / assembly initialization & cleanup.state/in-prA PR is open for this issue.type/regressionRegression from a previous release.

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions