Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
minghan opened this issue Feb 18, 2025 · 2 comments · Fixed by #5070

Comments

@minghan
Copy link
Member

minghan commented Feb 18, 2025

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.

@Youssef1313
Copy link
Member

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

@Youssef1313
Copy link
Member

This regression started from 3.6.0 (likely PR: #3339)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants