Surefire doesn't launch test in src/main/java

前端 未结 2 1339
死守一世寂寞
死守一世寂寞 2020-12-15 05:07

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

相关标签:
2条回答
  • 2020-12-15 05:27

    Since the test classes have now been placed in src/main/java, it is likely that they are getting compiled during the compile phase to target/classes.

    So, though surefire is configured to indicate that the test source location is src/main/java, it would still look for test classes in target/test-classes, since this is the default location for test classes.

    You could try specify testClassesDirectory parameter suitably and see if it works.

    Also, I think you may have misinterpreted the recommendation in the maven jar plugin documentation. I do not believe they suggest moving test sources to src/main/java.

    0 讨论(0)
  • 2020-12-15 05:30

    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
    
    0 讨论(0)
提交回复
热议问题