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

前端 未结 4 452
-上瘾入骨i
-上瘾入骨i 2021-01-01 12:37

edit: note, question 288805 is similar, however, I specifically am asking how does MSTest choose the default test order. Please

4条回答
  •  一生所求
    2021-01-01 12:57

    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.

提交回复
热议问题