gpt4 book ai didi

java - 为什么在 Maven 构建(安装)中默认不执行集成测试?

转载 作者:行者123 更新时间:2023-12-01 20:56:39 25 4
gpt4 key购买 nike

据我了解,默认情况下(这意味着没有任何故障安全插件的显式配置),maven 应该在执行目标“安装”时运行集成测试。请参阅https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference .

无论如何,似乎并非如此。所以,可能我误解了一些东西。

我在 src/test/java 中使用 JUnit 测试类 org.example.ExampleIT 和以下 POM 创建了一个最小的测试项目:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>mvn-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

构建(mvn install)成功,但未执行failsafe。请参阅以下日志摘录:

[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mvn-project ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mvn-project ---
(...)
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mvn-project
(...)
[INFO] BUILD SUCCESS

最佳答案

您实际上应该通过

执行插件
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>

您可以找到有关以下内容的更多信息:

http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html

关于java - 为什么在 Maven 构建(安装)中默认不执行集成测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42243080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com