I need to enforce TestClass order when executing tests with MSTest.
The order of TestClasses and tests within each class can be random, but MSTest should not pick a test from another TestClass until it is done executing ClassInitialize, all tests in the class, and ClassCleanup.
I have global AssemblyInitialize and AssemblyCleanup, therefore the following does not work, because it initializes the assembly for each test:
MSTest.exe /testcontainer:MyUnitTests.dll /resultsfile:report.trx /test:TestClass1 /test:TestClass2
I asked a similar question here, though it was not about test class execution order. Ordering tests can cause them to be brittle if the reason for the ordering is so that some sort of state can be setup/maintained. If this is the case with your tests, I would suggest instead writing them in a way that would be order-agnostic.
As regards your problem with the assembly-level code, a work around for the
AssemblyInitializeandAssemblyCleanupcan be as follows:Basically, you can force the assembly-level methods to fire only once.