我试图让maven-surefire-plugin只运行满足以下条件的所有测试:
*Test.java
,但不是*SomeTest.java
; *AnotherSomeTest.java
。有没有办法实现这个目标?
我已经尝试过包含字符串:
**/*Test.java, !%regex[.*(?!Another)SomeTest.*]
然而这不起作用。
答案 0 :(得分:3)
使用a regular expression可能有多种解决方案。最简单的就是配置
<includes>
<include>*AnotherSomeTest.java</include>
<include>%regex[.*(?<!Some)Test\.class]</include>
</includes>
这将匹配类名称与AnotherSomeTest
或Test
but not preceded by Some
结束的测试(负面的lookbehind <
只需要<
正确转义1}})。请注意,正则表达式匹配是通过.class
文件完成的,而传统的表达式是通过.java
文件完成的。
您可以使用
将其放入单个正则表达式中<include>%regex[.*(?<!(?<!Another)Some)Test\.class]</include>
选择所有以Test
结尾的测试,而不是Some
之前没有Another
的测试,但它可能不会更清晰。
另一个替代方法是使用multiple formats into one,它自插件版本2.19和JUnit 4或TestNG起作用。这对命令行非常有用:
<include>%regex[.*(?<!Some)Test\.class], *AnotherSomeTest.java</include>