java Maven (surefire) 测试插件排除不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25739969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven (surefire) test plugin excludes not working
提问by zbig
I have following configuration in my pom.xml
我的 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?
DocumentChangeSubscriberTest
是一个 arquillian 测试,我只想在指定的配置文件中运行。当我输入mvn install
所有测试时,即使DocumentChangeSubscriberTest
我想排除。如何从默认(匿名)配置文件中排除测试?
I tried <includes><include>...
and it works fine - only included tests were run.
我试过了<includes><include>...
,效果很好 - 只运行了包含的测试。
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?
我看到maven surefire 测试插件运行测试,即使它们被排除在外:但这对我不起作用。我也试过很多版本都maven-surefire-plugin
没有结果。有任何想法吗?
采纳答案by zbig
Ok, excluding tests works. It was as simple as mispelling my class name: DocumentChangeSubsriberTest.java
instead of DocumentChangeSubscriberTest.java
.
好的,排除测试有效。就像拼错我的班级名称一样简单:DocumentChangeSubsriberTest.java
而不是DocumentChangeSubscriberTest.java
.
Sorry.
对不起。
回答by G. Demecki
Although you already found an answer, there is a simpler solution.
尽管您已经找到了答案,但还有一个更简单的解决方案。
There is no need to use <excludes>
tag. Sticking to the maven naming conventionswould be enough. Just name your integration tests with *IT
suffix (for example: MyClassIT.java
) and let maven-failsafe-plugin
do its job.
没有必要使用<excludes>
标签。坚持maven 命名约定就足够了。只需使用*IT
后缀(例如:)命名您的集成测试,MyClassIT.java
然后maven-failsafe-plugin
就可以完成它的工作。
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:
请记住,maven-surefire-plugin
它旨在运行您的单元测试。这意味着所有具有以下通配符模式的测试类:
Test*.java
*Test.java
*TestCase.java
Test*.java
*Test.java
*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:
另一方面,maven-failsafe-plugin
旨在运行您的集成测试,并将自动包含具有以下通配符模式的所有测试类:
IT*.java
*IT.java
*ITCase.java
IT*.java
*IT.java
*ITCase.java
Your arquillian test is surely an integration test, so renaming it to DocumentChangeSubscriberIT.javawould solve all your problems ouf of the box.
您的 arquillian 测试肯定是一个集成测试,因此将其重命名为DocumentChangeSubscriber IT.java将解决您所有的问题。
btw. this postmay also be useful in terms of separation unit tests from the integration tests.
顺便提一句。这篇文章在将单元测试与集成测试分离方面也可能很有用。
Hope it helps somebody.
希望它可以帮助某人。
回答by src3369
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.
虽然问题已经解决,但万一有人遇到类似的排除问题,我还是发布了这个。我有一个类似的问题,其中我的排除不适用于 maven-failsafe-plugin。我使用 excludes 来排除运行一些集成测试。
I was using mvn verify
to run integration tests.
我mvn verify
用来运行集成测试。
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>"
如果我使用 -Dit.test 选项,则不起作用,
即mvn verify -Dit.test="<some_package>"
however DOES work correctly if I don't specify -Dit.test.
i.e. mvn verify
但是,如果我不指定 -Dit.test,它就可以正常工作。
IEmvn verify
回答by Neil
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.
我有一个类似的问题,只是为了让人们看看另一件事:我的 maven-surefire-plugin,正如上面描述的人,意外地声明<reporting><plugins><plugin>....</plugin></plugins></reporting>
在<build><plugins><plugin>...</plugin></plugins></build>
. 顶部<reporting>
和<build>
规格位于页面上方和下方,因此可以验证是否有人遇到相同的错误。
回答by nmartinez
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?
这个问题已经在这个线程中得到了回答(或者至少是一个非常相似的问题):如何在 maven 安装目标中跳过测试,同时在 maven 测试目标中运行它们?
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).
看看吧,或许有帮助!简单的答案是,如果不使用自定义配置文件,您尝试做的事情就不是一个选项(但在该线程中更好地解释了这一点)。