Maven (surefire) test plugin excludes not working

2020-07-06 04:03发布

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?

5条回答
聊天终结者
2楼-- · 2020-07-06 04:46

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

查看更多
老娘就宠你
3楼-- · 2020-07-06 04:50

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.

查看更多
Bombasti
4楼-- · 2020-07-06 04:50

I had a similar problem, just to throw out another thing for people to look at: My maven-surefire-plugin, as person described above, was accidentally declared under <reporting><plugins><plugin>....</plugin></plugins></reporting> but of course needed to be under <build><plugins><plugin>...</plugin></plugins></build>. The top <reporting> and <build> specs were higher up and off the page so something to verify if anyone gets this same error.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2020-07-06 04:50

This question was already answer in this thread (or at least a very similar one): How can I skip tests in maven install goal, while running them in maven test goal?

Take a look, it might be helpful! The simple answer is that what you are trying to do it's not an option without using a custom profile (but it's way better explained in that thread).

查看更多
Melony?
6楼-- · 2020-07-06 04:55

Ok, excluding tests works. It was as simple as mispelling my class name: DocumentChangeSubsriberTest.java instead of DocumentChangeSubscriberTest.java.

Sorry.

查看更多
登录 后发表回答