I'm using [ClassInitialize]
and [ClassCleanup]
tags from Microsoft.VisualStudio.TestTools.UnitTesting.
MSTest 2.0
I have a test class with tests that require my app to be in a different mode than usual.
I turn the mode on in [ClassInitialize]
and off in [ClassCleanup]
.
This doesn't work, as I learned from a comment to this answer: there's no guarantee that the execution of [ClassCleanup]
happens before any other tests are started. This is bad because in another class i have tests that require for the mode to be turned off. The mode doesn't get turned off in time and they fail.
I could turn the mode on/off for every test individually, but this is the very last option, because it takes a lot of time.
I could move the class to it's own assembly, but i don't really want to do that either.
I fixed it by turning the mode off in [ClassInitialize]
of the class that requires it to be off.
But i need to know, does [ClassInitialize]
share the same unintuitive behavior with [ClassCleanup]
, or is it guaranteed to NOT run before any previous tests are finished? That would make the first tests fail.
The very best solution would be to somehow force [ClassCleanup]
to run immediately after the first test class is all finished, but that's probably not possible.