Surefire不会在src/main/java中启动测试 [英] Surefire doesn't launch test in src/main/java

查看:92
本文介绍了Surefire不会在src/main/java中启动测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据来自maven-jar-plugin文档的此建议,将一些src/test/java移至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.

因此,我创建了my-project-test,将其移动到测试类中,并配置surefire以指定测试类目录=>

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>

但是当我启动mvn测试时,将执行0个测试=>

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

Results :

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

问题与此相同=> Maven不会找到要运行的JUnit测试,但是解决方案(配置surefire maven插件)对我不起作用.

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.

推荐答案

maven surefire插件的好配置是=>

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

这篇关于Surefire不会在src/main/java中启动测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆