ClassCleanup is not skipped when ignored and ClassInitialize is not present
jbne opened this issue · comments
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](https://private-user-images.githubusercontent.com/99751010/337020512-a97f471b-fa67-44d3-9fae-c1fd3c58f8dc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg5MDU5NTMsIm5iZiI6MTcxODkwNTY1MywicGF0aCI6Ii85OTc1MTAxMC8zMzcwMjA1MTItYTk3ZjQ3MWItZmE2Ny00NGQzLTlmYWUtYzFmZDNjNThmOGRjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjIwVDE3NDczM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI2N2Y3MjdiZjVmYTNlMjRlODk1OTc1ODY2NGJiYzFkMjY3ZjMwN2M3NzNjOTUwOGE3NzJlNDNmN2Y2NGMyY2YmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.YeBakpX03GtalCYs27dnjufLwb5bc80L3UYVr7-d9LI)
![image](https://private-user-images.githubusercontent.com/99751010/337021837-1aae4938-7456-4001-9e0b-0c7087deb77d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg5MDU5NTMsIm5iZiI6MTcxODkwNTY1MywicGF0aCI6Ii85OTc1MTAxMC8zMzcwMjE4MzctMWFhZTQ5MzgtNzQ1Ni00MDAxLTllMGItMGM3MDg3ZGViNzdkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjIwVDE3NDczM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTIwZTA4M2FiZmMyNjNmM2JiMDYyZGVmZTc3ZGNjYWJhZDEyMjA0YzMzMTNjMmU5MWE1YTk2OTE2NWFhMDZmNzUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.lCqzTCmuUwFu_il3YV4uIAWw5wIiucsXqmThPO-1LYo)
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?
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?
@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.
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.