What is the sequence of events in a full MSTest run of unit tests in C # inside Visual Studio (Ctrl + R, A)?
Here is what I think so far:
- 1 - Executes
[AssemblyInitialize] - 2 - Randomly runs a
[ClassInitialize] - 3 - Run the class
[TestInitialize] - 4 - Randomly runs a
[TestMethod] from this class - 5 - runs the class
[TestCleanup] - Repeat 3 through 5 for each TestMethod in the class.
- Repeat 2-5 for each test class.
- 6 - runs all classes
[ClassCleanup] methods - 7 - Executes
[AssemblyCleanup]
But I think that VS can initialize several classes at once, and then arbitrarily run TestMethods. Should tests be standalone throughout the class or throughout the test project or even the entire solution? Knowing the exact sequence of events should answer these questions.
UPDATE:
I did some tests and found that this is really the order in which events occur, with the exception of # 3 - 5, where ANY test from ANY class can be run. Visual Studio seems to run one test at a time in sequence. However, one should not rely on this for the reasons stated in the accepted answer.
source share