Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I control the order of execution of tests in Maven?

Tags:

I need to run tests in order. I fail to find this adequately documented anywhere. I would prefer to do this from command line. Something like

 mvn -Dtest=test1,test2,test3,test5 test 

How do I do this?

like image 766
niken Avatar asked Aug 22 '12 14:08

niken


People also ask

In which order test cases should be run?

This means that the test data creation scenario needs to be run first, otherwise the subsequent scenarios will fail. Using Background is not an option, because those steps are run before each individual scenario, whereas we want to run the test data creation steps once every feature.

Which JUnit annotation allows you to define order of execution for the test methods?

Annotation Type FixMethodOrder. This class allows the user to choose the order of execution of the methods within a test class.

Do Java tests run in order?

By default, JUnit executes tests in a specific order of its own, but not predictable. JUnit 5 allows programmers to override that default, to run tests in a determined order: alphanumeric order or numeric order.


1 Answers

You can't specify the run order of your tests.

A workaround to do this is to set the runOrder parameter to alphabetical.

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-surefire-plugin</artifactId>     <configuration>         <runOrder>alphabetical</runOrder>     </configuration> </plugin> 

and then you need to have rename your tests to obtain the expected order.

However it isn't a good idea to have dependent tests. Unit tests must be fIrst.

like image 117
gontard Avatar answered Sep 19 '22 20:09

gontard