Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
721 views
in Technique[技术] by (71.8m points)

unit testing - Surefire doesn't launch test in src/main/java

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}srcmainjava</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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The good configuration for maven surefire plugin is =>

<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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...