Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a set of tests only run as ordered tests?

I have never done ordered tests as I am of the beleif that it's not good practice. Where I work I am told to do them ,so let's cast aside what's good or bad practice.

I am new to msTests so could you help me here.

I have 10 tests and have to run in a particular order or some of them will fail.

  1. I have created a Basic test class and added all the 10 tests.
  2. I have created an Ordered test and moved to the right in the order I want to execute them.All fine.
  3. Run the tests but MsTest runs the tests twice.Once the ordered tests all successed!! But also runs the same tests in no particular order

Am I missing the obvious if I have a set of tests that are in order shouldnt those be removed as normal tests only run as ordered test.

How can I make a set of tests only run as ordered tests?

Any suggestions?

like image 273
user451259 Avatar asked Dec 29 '10 09:12

user451259


People also ask

What can we do to make your tests run in specific order?

We can use the @Order annotation to enforce tests to run in a specific order.

How do you run only few test cases?

By using grouping. You can create a group of task you want to execute and then make a suite for it and only those test cases will run. 2. By using enable and disable in the test method such that only the test case where enabled = true will execute and the test methods with enabled = false will not.


2 Answers

I too struggled with this one, but then I found the following documentation on MSDN: Ordered Test Overview

Apparently you don't get a list of the tests in the right order in the Test View. Instead the ordered test appears as a single test.

To me this was not a very good news as my tests will be run twice when I choose to "Run All Tests In Solution" (and fail the second time when run in the wrong order), but at least I got an explanation to why it is behaving this way.

like image 82
Nils Magne Lunde Avatar answered Oct 04 '22 14:10

Nils Magne Lunde


In VSTS, whenever you create an ordered test, it actually creates a separate file for that test. So, while executing you need to execute that ordered test file only. It will include all the tests in a particular order & during execution it will run as according to it only.

like image 31
Atulsh Avatar answered Oct 04 '22 14:10

Atulsh