Launch JUnit4 test package in Maven using maven-fail-safe plugin

I have a JUnit 4 test suite that contains several test classes in the order in which they should be run (our integration tests must run in a specific order).

If I use the maven-fail-safe plugin without any configuration, it will run the test, but not in the correct order. However, if I installed the plugin to run the test suite, the tests will not run.

Can I run a test suite using a secure plugin? if so, where did I go wrong!

Code below:

@RunWith(Suite.class) @SuiteClasses({ TestCase1.class, TestCase2.class, ... TestCaseN.class, }) public class IntegrationSuite { //Do Nothing. } 

and from pom.xml:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.9</version> <configuration> <includes> <include>IntegrationSuite.java</include> </includes> </configuration> <executions> <execution> <id>integration-test</id> <goals> <goal>integration-test</goal> </goals> </execution> <execution> <id>verify</id> <goals> <goal>verify</goal> </goals> </execution> </executions> </plugin> 

Thanks:)

+6
source share
2 answers

The Failsafe plugin supports the runOrder (click) parameter since version 2.7 (most recently). There are not many options, you cannot specify the order explicitly, but you can set it to "alphabetical" and rename your test classes to reflect the order of execution.

May I also say that the fact that a test is dependent on each other is a (test) smell of code ; this is not good, as it is a short way to developing an unattainable test suite and abandoning it, finally, when its complexity rises above human understanding. In addition, it may not detect errors, as this is the result of one selected execution path.

By the way, I prefer to include tests like this with a double asterisk:

 <includes> <include>**/IntegrationSuite.java</include> </includes> 
+10
source

maven-surefire-plugin can also be used as the code below:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</version> <configuration> <includes> <include>**/IntegrationSuite.java</include> </includes> </configuration> </plugin> 
0
source

Source: https://habr.com/ru/post/899451/


All Articles