我的目录结构如下:
src/integrationTest/java
src/test/java
src/main/java
我试图获得集成测试的安全性,但是没有按照我想要的方式这样做。
我试过这个:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<testSourceDirectory>src/integrationTest/java</testSourceDirectory>
<testClassesDirectory>${project.build.directory}/it-classes</testClassesDirectory>
</configuration>
</plugin>
和此:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>src/integrationTest/**/*.java</include>
</includes>
</configuration>
</plugin>
无济于事; failsafe没有找到要运行的测试。
我已经能够使用build-helper-maven插件添加测试源目录,然后failafe运行测试。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-integration-test-source-as-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integrationTest/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
然而,现在的问题是,surefire现在也将测试作为单元测试运行。当故障安全应该能够找到测试时,似乎没有必要使用另一个插件;我宁愿不需要使用build-helper maven插件并配置surefire来排除该路径。
我做错了什么?
答案 0 :(得分:4)
默认情况下,failsafe配置为仅include IT * .java,* IT.java或* ITCase.java。同时,仅编译来自RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ product.php?pageslug=$2&categoryslug=$1 [L,QSA]
的测试源。您需要修改这两种行为。
使用src/test/java
添加build-helper-maven-plugin
作为src/integationTest/java
自动提取的测试源。 (你已经在上一次尝试中完成了这项工作。)
指示maven-compiler-plugin
排除您的集成测试(请参阅下面的示例)或仅包含非集成测试(请参阅default includes)。
直接maven-surefire-plugin
仅包含您的集成测试,而不是默认包含。
maven-failsafe-plugin
实际上使用<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<excludes>
<exclude>**/*Stuff.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*Stuff.java</include>
</includes>
</configuration>
</plugin>
也可能会限制每个测试插件的范围,但您必须对testClassesDirectory
进行更改才能将类输出到不同的文件夹,可能会将其分割为maven-compiler-plugin
执行到两个,所以也许这不值得努力。
答案 1 :(得分:0)
使用以下配置对驻留在src/test/groovy
中的Groovy进行了有效的集成测试:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<executions>
<execution>
<id>spock-integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<failIfNoTests>true</failIfNoTests>
<testSourceDirectory>${project.basedir}/src/test/groovy</testSourceDirectory>
<includes>
<include>**/*Specification</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
请注意,<include>
中的模式不包含文件扩展名(**/*Specification.groovy
不起作用)