What's the sequence of events in a full MSTest run of unit tests in C# inside Visual Studio (Ctrl+R, A)?
Here's what I think so far:
- 1 - Runs
[AssemblyInitialize]
- 2 - Randomly runs a
[ClassInitialize]
- 3 - Runs the class
[TestInitialize]
- 4 - Randomly runs a
[TestMethod]
from that class - 5 - Runs the class
[TestCleanup]
- Repeat 3 through 5 for each TestMethod in the class
- Repeat 2 through 5 for each test class
- 6 - Runs all classes
[ClassCleanup]
methods - 7 - Runs
[AssemblyCleanup]
But I think VS might initialize multiple classes at once and then randomly run TestMethods. Should the tests be autonomous across its class or across the whole test project, or even the whole solution? Knowing the exact sequence of events should answer those questions.
UPDATE:
I did some tests and found that it is indeed the order in which events occurs, except for #3 to 5 where ANY test from ANY class could run. Visual Studio seems to sequentially run one test at a time. However, one should not rely on this for reasons explained in accepted answer.