testfx icon indicating copy to clipboard operation
testfx copied to clipboard

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

Open minghan opened this issue 1 year ago • 2 comments

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.

minghan avatar Feb 18 '25 17:02 minghan

Thank you for reporting this @minghan. I'm able to reproduce this, and will investigate.

Youssef1313 avatar Feb 18 '25 17:02 Youssef1313

This regression started from 3.6.0 (likely PR: https://github.com/microsoft/testfx/pull/3339)

Youssef1313 avatar Feb 19 '25 07:02 Youssef1313