11

Refer following links - GitHub discussion on how to separate Integration Tests and Unit Tests

As a result, I tried this --

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> <include>**/*Tests.java</include> <include>**/*Test.java</include> </includes> <excludes> <exclude>**/Abstract*.java</exclude> <exclude>**/IT*.java</exclude> <exclude>**/*IT.java</exclude> <exclude>**/*ITCase.java</exclude> <exclude>**/*IntegrationTest.java</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> <configuration> <includes> <include>**/IT*.java</include> <include>**/*IT.java</include> <include>**/*ITCase.java</include> <include>**/*IntegrationTest.java</include> </includes> </configuration> </execution> </executions> </plugin> 

This is working good to some extent. Meaning, surefire doesn't execute Integration tests and Failsafe doesn't execute unit tests.

But, when I run, mvn verify or mvn integration-test, the sure-fire plugin is also used.


Required Outcome: When run mvn integration-test, Unit test shouldn't be run.


The below three images are for mvn verify

Integration Test:

Integration Test

Tests Run

Unit Tests:

Unit Test

The below image is when I ran mvn test

Unit Tests

4
  • Follow the default naming schema and don't add several includes/excludes etc. cause the defaults for maven-surefire-plugin and maven-failsafe-plugin are working well...Conventions over configuration is the pardigm...So only configure something if you really need. Otherwise keep the defaults. Commented Apr 18, 2017 at 11:23
  • FailSafe Naming convention. I didn't know this existed until you mentioned. Commented Apr 18, 2017 at 11:35
  • @khmarbaise But, does sunfire exclude default of failsafe plugin? Commented Apr 18, 2017 at 11:35
  • 1
    I recommend a look into the docs like here: maven.apache.org/surefire/maven-surefire-plugin/… The exclude is not neccessary...cause maven-surefire and maven-failsafe working via includes instead. See maven.apache.org/surefire/maven-failsafe-plugin/… Commented Apr 19, 2017 at 8:04

2 Answers 2

9

Maven has a build lifecycle made up out of several phases. When you call a particular one, all phases before that one will be executed first. See https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

There are two ways how you could solve what you want:

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

Comments

1

Both goals verify and integration-test defined in maven-failsafe-plugin runs integration test cases with surefire. Here things are working as expected and as per guideline provided. pls refer this link for more details:

1 Comment

This is true. Thanks. But, it doesn't actually solve my core problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.