2

Is it possible to configure Maven so that it executes all test classes separately as I would execute them from command line:

mvn -Dtest=Test1 test && mvn -Dtest=Test2 test && mvn -Dtest=Test3 test 

I thought it could be achievable with maven surefire plugin. With configuration like:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${maven-surefire-plugin.version}</version> <executions> <execution> <id>test1</id> <goals> <goal>test</goal> </goals> <configuration> <includes> <include>**/Test1.java</include> </includes> </configuration> </execution> <execution> <id>test2</id> <goals> <goal>test</goal> </goals> <configuration> <includes> <include>**/Test2.java</include> </includes> </configuration> </execution> <execution> <id>test3</id> <goals> <goal>test</goal> </goals> <configuration> <includes> <include>**/Test3.java</include> </includes> </configuration> </execution> </executions> </plugin> 

But it doesn't work

3
  • Why want you do that? Commented Aug 2, 2021 at 9:29
  • @Jens There is a test class that fails when executed during standard build. However it runs successfully when executed separately and it doesn't affect the test quality. Commented Aug 2, 2021 at 9:33
  • 1
    If it fails during the standard build, it should be repaired or eliminated. Commented Aug 2, 2021 at 9:45

1 Answer 1

2

The option

 <configuration> <reuseForks>false</reuseForks> </configuration> 

solved the problem as it forced each test to run on a separate VM

Sign up to request clarification or add additional context in comments.

3 Comments

If that's the solution your tests keeping static states etc... you should check the test in depth...
@khmarbaise It all started with a @SpyBean that did its job fine when the corresponding test class ran separately. But when the test ran together with other tests (via mvn package or mvn test) the @SpyBean stopped to intercept method calls. Maybe I'll ask another question related to this problem, but I wanted to fix it as soon as possible. Besides all the tests should normally be executed separately without any problems. If they don't - something is wrong with test design.
@khmarbaise I've created another question related to the problem here stackoverflow.com/questions/68620654/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.