Maven (surefire) test plugin excludes not working

zbig picture zbig · Sep 9, 2014 · Viewed 11.7k times · Source

I have following configuration in my pom.xml

<build>
  <plugins>
      <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.17</version>
          <configuration>
              <excludes>
                  <exclude>**/DocumentChangeSubscriberTest.java</exclude>
              </excludes>
          </configuration>
      </plugin>
      (...)

DocumentChangeSubscriberTest is an arquillian test that I want to run only in specified profile. When I type mvn install all tests are run, even DocumentChangeSubscriberTest that I want to exclude. How to exclude test from the default (anonymous) profile?

I tried <includes><include>... and it works fine - only included tests were run.

I saw maven surefire test plugin runs tests even if they are excluded: but this is not working for me. I also tried many versions of maven-surefire-plugin without result. Any ideas?

Answer

G. Demecki picture G. Demecki · Sep 18, 2014

Although you already found an answer, there is a simpler solution.

There is no need to use <excludes> tag. Sticking to the maven naming conventions would be enough. Just name your integration tests with *IT suffix (for example: MyClassIT.java) and let maven-failsafe-plugin do its job.

Keep in mind that maven-surefire-plugin is designed to run your unit tests. That's mean all test classes that with the following wildcard patterns:

  1. Test*.java
  2. *Test.java
  3. *TestCase.java

On the other hand, maven-failsafe-plugin is designed to run your integration tests, and will automatically include all test classes with the following wildcard patterns:

  1. IT*.java
  2. *IT.java
  3. *ITCase.java

Your arquillian test is surely an integration test, so renaming it to DocumentChangeSubscriberIT.java would solve all your problems ouf of the box.

btw. this post may also be useful in terms of separation unit tests from the integration tests.

Hope it helps somebody.