gpt4 book ai didi

maven - 在 Maven 中,是否可以将集成测试保存在与单元测试不同的文件夹中?

转载 作者:行者123 更新时间:2023-12-03 11:28:40 24 4
gpt4 key购买 nike

Maven and Integration Testing页面上写着:

The Future Rumor has it that a future version of Maven will support something like src/it/java in the integration-test phase, in addition to src/test/java in the test phase.



但那是在 2011 年 12 月 11 日。这已经发生了吗?

this answer"Run maven test not in default src/test/java folder"它提到设置 <testSourceDirectory> ,他们这样做是否只是为了集成测试(即 integration-test 阶段)?

我正在寻找使用 Maven FailSafe plugin并避免重命名一堆集成测试或使用仍处于试验阶段的 JUnit @Categories .

最佳答案

您可以将 IT 放入不同的文件夹,如下所示:

.
|-- pom.xml
`-- src
|-- it
| `-- java
| `-- com
| `-- soebes
| `-- maui
| `-- it
| `-- BitMaskIT.java
|-- main
| `-- java
| `-- com
| `-- soebes
| `-- maui
| `-- it
| `-- BitMask.java
`-- test
`-- java
`-- com
`-- soebes
`-- maui
`-- it
`-- BitMaskTest.java

需要以下内容才能使编译器等知道文件夹。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>process-resources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

真正运行 IT 需要以下内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

这意味着您可以在同一模块中进行集成,但缺点是运行集成测试使用与单元测试相同的资源。更好的解决方案是创建一个单独的 maven 模块,您可以在其中将集成测试放入常用文件夹 src/test/java等等,并且只配置 maven-failsafe-plugin。

关于maven - 在 Maven 中,是否可以将集成测试保存在与单元测试不同的文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17865088/

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