Maven 集成测试为打包的jar创建文件
我在集成测试中使用rest-assured生成SpringRestDocs片段。 使用maven和默认为集成测试和验证阶段的故障保护插件。问题是,Maven 集成测试为打包的jar创建文件,maven,asciidoctor,spring-restdocs,Maven,Asciidoctor,Spring Restdocs,我在集成测试中使用rest-assured生成SpringRestDocs片段。 使用maven和默认为集成测试和验证阶段的故障保护插件。问题是,asciidoctor-maven-plugin(从代码段生成最终的HTML文件)和maven-resources-plugin(将最终的HTML文件复制到正确的位置)在prepare-package中的集成测试之前运行 使用该AscidActor自然会失败,因为代码段尚未生成 如果我将AscidActor配置为在集成后测试中运行,它会成功,但是完成的
asciidoctor-maven-plugin
(从代码段生成最终的HTML文件)和maven-resources-plugin
(将最终的HTML文件复制到正确的位置)在prepare-package
中的集成测试之前运行
使用该AscidActor自然会失败,因为代码段尚未生成
如果我将AscidActor配置为在集成后测试中运行,它会成功,但是完成的HTML页面不在我的jar中,因为jar已经在包
阶段创建
因此,我觉得唯一的选择是在测试
阶段运行我的集成测试(可能使用surefire而不是failsafe)
我还可以将与文档相关的测试从其余的集成测试中分离出来,但实际上我喜欢将它们放在看似正确的位置
我想知道是否有我忽略的最佳实践?
集成测试是否应该永远不会产生放入jar中的东西
在我看来,maven中的集成测试是用于跨jar测试的(因此在包之后运行它们)。我并不是在使用它们,只是为了在一个jar中包含多个部分(尤其是DB)的更大测试
我想要的是:
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<skip>${skipSurefire}</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*IT.java</include>
<include>**/*E2ET.java</include>
</includes>
</configuration>
</plugin>
<!-- Compile API documentation -->
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.8</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>${spring-restdocs.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- Package API documentation -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/public/docs
</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven surefire插件
2.22.1
${skipSurefire}
org.apache.maven.plugins
maven故障保护插件
2.22.1
集成测试
验证
**/*IT.java
**/*E2ET.java
org.ascidoctor
AscidActor maven插件
1.5.8
生成文档
准备包装
过程ascidoc
html
书
org.springframework.restdocs
弹簧复位器
${spring restdocs.version}
maven资源插件
2.7
复制资源
准备包装
复制资源
${project.build.outputDirectory}/public/docs
${project.build.directory}/生成的文档
集成测试阶段和验证阶段只是和目标的默认绑定。您还可以将集成测试绑定到测试
阶段:
。。。
maven故障保护插件
...
集成测试
测试
集成测试
这样可以达到你喜欢/需要的顺序