how does MSTest determine the order in which to run test methods?

纵然是瞬间 提交于 2019-11-30 11:06:37

I believe that MSTest executes test methods ordering them by their 'ID' (seems to be their full namespace).

I created a TestProject1 wich contains 4 unt tests (UnitTest1, ...2, ...A, ...B). Each unit test contains 5 test methods (TestMethodA, ...B, ...1, ...2, ...3). They were declared with random order inside their test classes. Now, every time I run MSTest, the tests are executed with the same order:

TestProject1.UnitTest1.TestMethod1
TestProject1.UnitTest1.TestMethod2
TestProject1.UnitTest1.TestMethod3
TestProject1.UnitTest1.TestMethodA
TestProject1.UnitTest1.TestMethodB
TestProject1.UnitTest2.TestMethod1
TestProject1.UnitTest2.TestMethod2
TestProject1.UnitTest2.TestMethod3
TestProject1.UnitTest2.TestMethodA
TestProject1.UnitTest2.TestMethodB
TestProject1.UnitTestA.TestMethod1
TestProject1.UnitTestA.TestMethod2
TestProject1.UnitTestA.TestMethod3
TestProject1.UnitTestA.TestMethodA
TestProject1.UnitTestA.TestMethodB
TestProject1.UnitTestB.TestMethod1
TestProject1.UnitTestB.TestMethod2
TestProject1.UnitTestB.TestMethod3
TestProject1.UnitTestB.TestMethodA
TestProject1.UnitTestB.TestMethodB

The only way to change that order is to rename one TestClass or a TestMethod. If for example I rename the TestMethodB, of the UnitTest1, to TestMethod4 it will be executed before TestMethodA.

To see the IDs of your test methods open the 'Test View' window from VS and then right click on a column header (e.g. Test Name) --> "Add/Remove Columns..." and add 'ID' column.

The MSDN says ;-)

How to: Create an Ordered Test

http://msdn.microsoft.com/en-us/library/ms182631.aspx

MSTest.exe command-line options

http://msdn.microsoft.com/en-us/library/ms182489(v=vs.120).aspx

As for VSTest execution order. Here is how it's organized in your TestProject:

  1. Sort cs-files in your project by their CREATION Time ASC
  2. Method Position in each file

For example, you have 3 cs files in project.

  • UnitTest1.cs - created 01/01/1970 with methods TestMethod05 and TestMethod03
  • UnitTest2.cs - created 05/01/1970 with method TestMethod02.
  • UnitTest3.cs - created 03/01/1970 with method TestMethod01.

Then order of executing test is this:

    TestProject1.UnitTest1.TestMethod05
    TestProject1.UnitTest1.TestMethod03
    TestProject1.UnitTest3.TestMethod01
    TestProject1.UnitTest2.TestMethod02

You can see the 'default order' using command:

vstest.console.exe TestProject1.dll /ListTests

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!