Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Does MSTEST/Visual Studio 2008 Team Test Decide Test Method Execution Order?

I was under the impression that the test methods in a unit test class would be executed in the order that they appear in the class file. Apparently this is not true. It also doesn't appear to be purely based off of alphabetical order either. How does MSTEST decide execution order?

EDIT: I was able to track down the answer after digging a bit. See below.

like image 364
Daniel Auger Avatar asked Nov 13 '08 23:11

Daniel Auger


People also ask

Do unit tests run in order?

Occasionally, you may want to have unit tests run in a specific order. Ideally, the order in which unit tests run should not matter, and it is best practice to avoid ordering unit tests. Regardless, there may be a need to do so. In that case, this article demonstrates how to order test runs.

Which attribute should be used to mark a method as test method in MSTest testing?

The TestClass attribute denotes a class that contains unit tests. The TestMethod attribute indicates a method is a test method.

Which annotation identifies the method that is called just once after the last test in TestClass in MSTest is executed?

@After annotation is used on a method containing java code to run after each test case.


2 Answers

I was able to track down the answer.

According to Microsoft employee Guillermo Serrato:

MSTest executes all tests synchronously, the order is nondeterministic

like image 161
Daniel Auger Avatar answered Jun 23 '23 07:06

Daniel Auger


Sorting in Test View, or test list editor causes them to appear like you have control -- it's just a by product of the implementation. We make no attempt to actually execute them in a specific order (We've gone back and forth on the "allow order", and "randomly order").

If you really need order, that is what ordered tests are for. These are available in all editions where Unit Test is available -- either use the Test/New Test menu, or right click the test project and create a "ordered test"

like image 43
Dominic Hopton Avatar answered Jun 23 '23 09:06

Dominic Hopton