我有一个Maven Java项目,我在其中添加了pom:
<build>
....
<plugin>
<!-- adding second test source directory (just for integration tests) -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${plugin.build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-integration-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resource</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/integration-test/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</build>
InteliJ将我在兼容性测试下的java和资源文件夹识别为代码文件夹,但Eclipse并没有。 有没有办法在导入项目时将这些文件夹添加为代码文件夹?
答案 0 :(得分:0)
尝试右键单击上下文菜单中Project Explorer
选择Build Path
选项中的文件夹,然后点击选择Use as Source Folder
后出现的菜单中的Build Path
。
答案 1 :(得分:0)
我建议不要在Maven中使用自己的目录布局,因为这会导致很多问题,而且你总是要围绕它进行配置。 Just stick to the standard.
src/test/java
中。此时您不必配置任何内容,默认情况下会采用此路径。IT*.java
和单元测试UT*.java
。 maven-surefire-plugin
执行单元测试并且maven-failsafe-plugin
执行了集成测试。您可以定义用于标识测试类的文件名模式。您还可以创建仅运行UT或仅运行IT的配置文件。
<project>
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<includes>
<include>**/UT*.java</include>
</includes>
<excludes>
<exclude>**/IT*.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<configuration>
<includes>
<include>**/IT*.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
进一步阅读:http://tomaszdziurko.pl/2013/01/running-unit-tests-integration-tests-separately-maven-testng/
还有一篇关于正确使用集成测试的文章:http://zeroturnaround.com/rebellabs/the-correct-way-to-use-integration-tests-in-your-build-process/