Maven Profile不会运行适当的测试(Maven Profile does not run appropiate tests)

编程入门 行业动态 更新时间:2024-10-28 11:24:20
Maven Profile不会运行适当的测试(Maven Profile does not run appropiate tests)

我已经配置了一个仅运行集成测试的配置文件,但它仍在运行所有测试。 这是配置:

<profile> <id>integration</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <executions> <execution> <id>integration-test</id> <goals> <goal>test</goal> </goals> <phase>test</phase> <configuration> <includes> <include>**/*IT.java</include> </includes> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>

我尝试使用正则表达式,如http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html中所解释的那样,但我觉得这不起作用。 我如何只使用IT.java运行测试?

谢谢

I have configured a profile for running only integration tests but it is still running all tests. This is the configuration:

<profile> <id>integration</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <executions> <execution> <id>integration-test</id> <goals> <goal>test</goal> </goals> <phase>test</phase> <configuration> <includes> <include>**/*IT.java</include> </includes> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>

I tried with regex like explained at http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html but I got this not working. How do I get only tests running that end with IT.java?

Thanks

最满意答案

您尚未重新配置surefire运行,而是在生命周期中添加了另一个。 那样,surefire:测试运行两次,一次使用默认执行ID( default-test ),一次使用新执行( integration-test )

如果您只想更改正在运行的测试,可以使用:

<profile> <id>integration</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <includes> <include>**/*IT.java</include> </includes> </configuration> </plugin> </plugins> </build> </profile>

这只会重新配置现有的执行。

尽管如此,正如khmarbaise已在评论中写道,仅仅使用maven-failsafe-plugin就更有意义了。 如果你真的想跳过正常的单元测试(为什么你还想要它?),你可以在你的配置文件中明确禁用skipTests (使用skipTests -configuration)。

You have not reconfigured the surefire run, but instead added another one to the lifecycle. That way, surefire:test runs twice, once with default execution id (default-test) and once with your new execution (integration-test)

If you simply want to change the tests being run, you could use:

<profile> <id>integration</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <includes> <include>**/*IT.java</include> </includes> </configuration> </plugin> </plugins> </build> </profile>

Which would only reconfigure the existing execution.

Still, as khmarbaise already wrote in a comment, it makes much more sense to simply use the maven-failsafe-plugin. If you really wanted to skip normal unit test (why would you want that, anyway?), you could explicitly disable surefire in your profile (using skipTests-configuration).

更多推荐

本文发布于:2023-07-19 20:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1186679.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   Profile   Maven   tests   appropiate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!