24

I needed to move some src/test/java to src/main/java according to this recommandation from maven-jar-plugin documentation => http://maven.apache.org/plugins/maven-jar-plugin/usage.html

I did so because, i used tests (helper) classes in another projects in test scope.

So i create my-project-test, moved in test classes, and configured surefire to specify test classes directory =>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <testSourceDirectory>${basedir}\src\main\java\</testSourceDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

But when i launched mvn test, 0 tests is executed =>

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

The problem is the same as this one => Maven does not find JUnit tests to run but the solution (configure surefire maven plugin) is not working for me.

4

2 に答える 2

30

Mavenのsurefireプラグインの適切な構成は=>です。

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testSourceDirectory>${basedir}/src/main/java/</testSourceDirectory>
                    <testClassesDirectory>${project.build.directory}/classes/</testClassesDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

Results :

Tests run: 20, Failures: 0, Errors: 0, Skipped: 0
于 2012-01-25T08:56:14.230 に答える
1

テスト クラスは に配置されているため、コンパイルフェーズsrc/main/java中に にコンパイルされる可能性があります。 target/classes

したがって、surefire は、テスト ソースの場所が であることを示すように構成されていますが、これはテスト クラスの既定の場所であるため、src/main/java引き続き でテスト クラスを探します。target/test-classes

testClassesDirectoryパラメータを適切に指定してみて、それが機能するかどうかを確認してください。

また、maven jar プラグインのドキュメントの推奨事項を誤解している可能性があると思います。彼らがテスト ソースを に移動することを提案しているとは思えませんsrc/main/java

于 2012-01-25T05:53:20.173 に答える