Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven (surefire) test plugin excludes not working

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?

like image 852
zbig Avatar asked Sep 09 '14 08:09

zbig


People also ask

Why Maven surefire plugin tests are skipped?

When the Surefire plugin reaches the test goal, it will skip the unit tests if the maven. test. skip properties is set to true . Another way to configure Maven to skip unit tests is to add this configuration to your project's pom.

How do I exclude test cases in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.

Why your JUnit 4 tests are not running under Maven?

Until JUnit 4, Maven will only run the test classes which are marked as public. We should note, though, that this won't be an issue with JUnit 5+. However, the actual test methods should always be marked as public. Here, we can notice that the test method is marked as private.

How do I get my Maven integration tests to run?

The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.


2 Answers

Although the question has been resolved, in-case someone is having similar issues with excludes, I am posting this. I had a similar issue where-in my excludes was not working for maven-failsafe-plugin. I was using excludes to exclude running some integration tests.

I was using mvn verify to run integration tests.

in my case,

 <excludes>
   <exclude>**/something/*Test.java</exclude>
</excludes>

DOES NOT work if I use the -Dit.test option
i.e. mvn verify -Dit.test="<some_package>"


however DOES work correctly if I don't specify -Dit.test.
i.e. mvn verify

like image 130
src3369 Avatar answered Oct 14 '22 21:10

src3369


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.

like image 37
G. Demecki Avatar answered Oct 14 '22 22:10

G. Demecki