microsoft / testfx

MSTest framework and adapter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ClassCleanup is not skipped when ignored and ClassInitialize is not present

jbne opened this issue · comments

commented

Describe the bug

The ClassCleanup method is executed when ClassInitialize is not present in the TestClass and either the TestClass is ignored or when all TestMethod in a TestClass are ignored.

Steps To Reproduce

Make a simple MSTest project that has a single ignored TestClass and no ClassInitialize method. See screenshots below.

Expected behavior

ClassCleanup should not run when the TestClass is ignored or when all TestMethod in that TestClass are ignored regardless of the presence of ClassInitialize.

Actual behavior

ClassCleanup is always run when ClassInitialize is not present in the TestClass, regardless of the Ignore attribute.

Additional context

image image

Are you reporting this because this is a regression (e.g. since last version. or since 2.x.x), or if this was always like this and you'd like it to change?

commented

I'm not sure if this is a regression, I would have to check. I reported it because it is a bit of a deviation in consistent behavior when ignoring all tests in a test class. ClassCleanup is skipped when ClassInitialize is present vs. ClassCleanup is not skipped when ClassInitialize is not present. That behavior also deviates from TestInitialize and TestCleanup, which are always skipped regardless of the presence of methods marked with TestInitialize/TestCleanup.

IMO it would make the most sense to skip both ClassInitialize and ClassCleanup if no tests need to run in a test class. There's no need for initialization or cleanup in that case.

Maybe this is intended behavior, in which case documentation might save users a bit of trouble.

@jbne I have just tried to reproduce and I don't see this behavior using 3.4.3, could you please provide a reproducer?

commented

@Evangelink As it turns out I was using older 2.x versions too, I updated them and confirmed I see the same thing. Attached is the sample project I used.

TestProject_MSTest.zip

Thanks! I can reproduce the issue, I didn't pay attention that adding a ClassInitialize was fixing the ClassCleanup issue you reported. We will work on a fix.