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:
[AssemblyInitialize]
[ClassInitialize]
[TestInitialize]
[TestMethod]
from that class[TestCleanup]
[ClassCleanup]
methods[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.
You are correct. This is indeed the order in which the code will be run. However, since tests should be completely independent, there are no guarantee that they will be run in order and that they will be run on a single thread. The framework could run multiple test at the same time.
You can force a specific test order through the use of test cases if you need too, but this is considered bad practice as test cases should be used to regroup tests together (tag them) instead.
To define a specific order for your tests, either create an ordered test (http://msdn.microsoft.com/en-us/library/ms182631.aspx) or create a match file and call mstest.exe for each test case in the specified order you desire (http://msdn.microsoft.com/en-us/library/ms182489(VS.80).aspx)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With