3

We've been running our tests created with SpecFlow using MSTest and the order of tests was determined by test id. So just starting test name with 1001_, 1002_ etc you could control execution order. Having an issue running same order with VStest. As claimed in another post the order of VSTest execution is below*. And the only obvious option is to create an "ordered test" container, which is not suitable for us. Wondering if there is a way to control order of tests with VSTest. Thanks

*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*

Razkar
  • 539
  • 5
  • 26
  • The reason that there isn't an easy way to do this is because the order of your tests shouldn't matter. Any test should be able to give you the same result at any time regardless of what tests have run before. My advice would be to make all your tests independent of one another so the order doesn't matter. – Ruben van Kruistum Jan 11 '18 at 07:23
  • 1
    That is true. You want your tests to be as independent as possible. But with some complicated UI tests, it sometimes makes sense to use previously run tests as a pre-setup, if you don't want to set up that data with some api methods or direct db manipulations. So it's an inevitable evil for some test suites. – Razkar Jan 25 '18 at 22:55
  • Why not create ".orderedtest" file and pass as one of the command line parameters? – Amittai Shapira Oct 23 '18 at 18:49
  • Ordered test don't get along with TestCategory tags too well – Razkar Oct 24 '18 at 19:03

0 Answers0