gpt4 book ai didi

java - Maven 故障安全 : followed guide, 但未在 "verify"上运行

转载 作者:太空宇宙 更新时间:2023-11-04 15:12:58 24 4
gpt4 key购买 nike

我正在尝试让 Maven 故障安全插件运行我的集成测试,但即使我已遵循 https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html 中的指南它不起作用。

我的maven项目(MvnTest)看起来像这样(源文件如下):

pom.xml
-src
-main
-java
-resources
-test
-java
SomeIT.java
SomeTest.java

mvn test 使用 sunfire 插件仅正确运行 SomeTest.java 中的测试。输出:

...
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MvnTest ---
[INFO] Surefire report directory: ...
...
Running SomeTest
Tests run: 1, Failures: 1

但是,mvn verify命令输出与mvn test完全相同的内容,这在两个方面是错误的:1)它调用sunfire,2)它运行SomeTest.java 中的测试,但应该只运行 SomeIT.java 中的测试 ( https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html )

我相信我已经遵循了正确使用故障保护的指南,但显然我一定错过了一些东西。我做错了什么?

源文件

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>MvnTest</groupId>
<artifactId>MvnTest</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>

SomeIT.java:

import org.junit.Test;
import static org.junit.Assert.assertTrue;

public class SomeIT {
@Test
public void test2() {
assertTrue(4 == 3);
}
}

SomeTest.java:

import org.junit.Test;
import static org.junit.Assert.assertTrue;

public class SomeTest {
@Test
public void test1() {
assertTrue(2 == 3);
}
}

最佳答案

在 pom.xml 中为 maven-failsafe-plugin 添加包含部分

看起来像:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

关于java - Maven 故障安全 : followed guide, 但未在 "verify"上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21138165/

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