Maven (surefire) test plugin excludes not working

二次信任 提交于 2019-12-09 17:07:06

问题


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?


回答1:


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.




回答2:


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

Sorry.




回答3:


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




回答4:


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:


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).



来源:https://stackoverflow.com/questions/25739969/maven-surefire-test-plugin-excludes-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!