Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control order in which ReSharper executes unit tests

Is there any way to tell ReSharper to execute a certain group of tests in a project before others? I still want the parallel execution and I don't need to control it per-method, just per-class will do. The test framework is MSTest if that makes a difference.

The reason I want to do this is that some tests work at a low level and are very fast, but other tests work at higher levels and are much slower. I want the fast tests to run first, because if they fail then I know there's something wrong and there's no point in continuing. However, ReSharper currently runs my slow tests first.

Edit: The tests are not run in alphabetical order for me (R# 7.1 on VS 2010). I have one source file per class. The tests within a class seem to be run in the order the methods appear in the source code, but I cannot figure out how R# determines the order of test classes. That's what I'm after, since slow and fast tests are in separate classes. That's not alphabetical either, but it is consistent from run to run.

Edit 2: OK, figured it out (see answer).

like image 472
EM0 Avatar asked Nov 26 '12 02:11

EM0


4 Answers

This seems like a bit of a hack, but I found that if I remove the files with the slow tests from the project and re-add them they then get run last. So it appears that R# keeps track of the order in which source files containing test classes were added and runs them in that order. (Editing the .csproj file to re-order the files had no effect, so it doesn't seem to use that.)

like image 55
EM0 Avatar answered Nov 18 '22 11:11

EM0


The reason I want to do this is that some tests work at a low level and are very fast, but other tests work at higher levels and are much slower.

I would suggest a couple of methods:

Split the tests into two separate projects. Put the "fast" tests into

YourProject.Test.Unit

and the slow tests in

YourProject.Test.Integration

Integration tests are normally tests which interact with other components (e.g.. a network, database, file system, etc) which could lead to slower test runs. It could be that your slower tests are accessing an external resource (we don't know that).

Or use @thersch's suggestion of using categories to mark out the slower tests. I would use the category method is your tests really are all unit tests, and thus it would not make sense to split them.

like image 21
Jason Evans Avatar answered Nov 18 '22 10:11

Jason Evans


It seems that test execution is in alphabetical order in form of .... So you could change your namespace/class names to match the test order. But I guess that is not an option for you.

Another option is to add tests to different test sessions in "Unit Test Sessions" window. Move fast tests to Session #1 and slow tests to session #2. Then you run only the one test session you need.

Not an option is to add TestCategory to your test methods (i.e.: [TestCategory("Fast"), TestMethod] and [TestCategory("Slow"), TestMethod]) and group your tests in Unit Test Sessions window by Categories. This has no effect to test order.

like image 2
thersch Avatar answered Nov 18 '22 11:11

thersch


Or, you could create a Test which orchestrates calls to other tests in the order that you want - So this test itself acts as a "session".

[TestMethod]
public void A_RunAllTests()
{
    Test1();
    Test2();
    .
    .

}
like image 1
Robin Maben Avatar answered Nov 18 '22 11:11

Robin Maben