This question regards unit testing in Visual Studio using MSTest (this is important, because of MSTest’s execution order). Both the method marked [TestInitialize] and the test class constructor will run before each test method.
So, the question is, what do you tend to do in each of these areas? Do you avoid performing certain activities in either? What is your reason: style, technical, superstition?
The constructor is just a structure provided by the language. Every test framework seems has its own controlled lifecycle “initialize”. You’ll probably only get into trouble using the constructor to mutate your locals.
MSTest: You get an entire new instance of the test class for every
TestMethod. This might be the only case where it’s ok to mutate your locals in the constructor, initializer, or test method and not affect the other test methods.MSpec: You only get one
EstablishandBecausefor all your assertions (It). So, don’t mutate your locals in your assertions. And don’t depend on mutations of locals in base contexts (if you use them).