不在默认的src/test/java文件夹中运行Maven测试

不在默认的src/test/java文件夹中运行Maven测试

问题描述:

我有一个包含pom.xml和一些JUnit测试的项目. pom.xml和单元测试均正确.但是问题是测试不在src/test/java文件夹中(我不能使用此文件夹).是否可以告诉maven从另一个源文件夹(也在此项目中)执行测试?

I have a project containing pom.xml and some JUnit tests. Both pom.xml and unit tests are corrects. But problem is that tests are not in src/test/java folder (I cannot use this folder). Is it possible to tell maven to execute tests from another source folder (which is also in this project)?

将这部分添加到pom中就足够了:

It is enough to add this part to your pom:

<project>
    ...
    <build>
        <testSourceDirectory>src/int-test/java</testSourceDirectory>
    </build>
    ...
</project>

测试源将在test-compile阶段进行编译,而maven-surefire-plugin也将找到测试类.

The test sources will be compiled during the test-compile phase and the maven-surefire-plugin will find the test classes too.