Maven默默地找不到要运行的JUnit测试 [英] Maven silently fails to find JUnit tests to run

查看:158
本文介绍了Maven默默地找不到要运行的JUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在IntelliJ中打开了一个新的Java项目,以Maven作为其构建工具,目前有一个类和一个JUnit 5测试类.当我指示IntelliJ单独或一起运行测试时,它可以工作.但是,当我转到终端并按mvn clean test或在IntelliJ中的Maven窗格中执行相同操作时,它将跳过测试.

I've got a new Java project open in IntelliJ with Maven as its build tool, with one class and one JUnit 5 test class at the moment. When I direct IntelliJ to run tests, individually or all together, it works. But when I go to the terminal and hit mvn clean test or do the same from the Maven pane within IntelliJ, it skips over the tests.

具有类似问题的提问者不同, ,我没有收到任何错误消息.找到测试类 并进行编译.我没有他遇到的同样的问题(文件命名不正确).

Unlike the questioner with this similar question, however, I'm not getting any error message. The test class is found and does compile. I do not have the same problem (incorrect file naming) that he had.

Stackoverflow问我为什么这不是这个问题.这是相同的问题,但他们的解决方案(自2016年起)不再正确.您不再需要添加提供者"依赖项.

Stackoverflow asks me why this isn't a duplicate of this question. It is the same problem, but their solution (from 2016) is no longer correct. You don't need to add the "provider" dependency anymore.

这是我的Maven输出中的相关部分:

Here's the relevant section of my Maven output:

[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ markovmodels ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\joe\foo\markovmodels\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ markovmodels ---
[INFO] Surefire report directory: C:\Users\joe\foo\markovmodels\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.648 s
[INFO] Finished at: 2019-08-13T09:02:53-04:00
[INFO] ------------------------------------------------------------------------

我不知道这是否有用,但是我发现未创建target/surefire-reports目录.

I don't know if it's a useful clue, but I observed that the target/surefire-reports directory was not created.

pom.xml中,我具有以下两个与测试相关的依赖项:

In the pom.xml I have these two test-related dependencies:

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.4.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.2</version>
        <scope>test</scope>
    </dependency>

它们是直接从另一个有效的项目中复制过来的.我尚未指定Surefire插件的版本或更改其任何默认值,因此有效的POM与我的其他项目相同(它使用maven-surefire-plugin版本2.12.4).测试源文件似乎位于正确的目录中,并且具有正确的命名约定. 我可能会犯什么错误?

They are directly copied over from another project which works. I have not specified a version of the Surefire plugin or changed any of its defaults, so the effective POM is the same as my other projects (it uses maven-surefire-plugin version 2.12.4). The test source file seems to be in the right directory and have the right naming convention. What mistake could I be making?

当前状态下的代码可以在Github上. /p>

The code at its current state can be here on Github.

推荐答案

这是maven-surefire-plugin

的问题

maven-surefire-plugin的默认版本出了点问题,我可以通过对其进行升级来修复它.我通过复制

It was an issue with the maven-surefire-plugin

There was something wrong with the default version of the maven-surefire-plugin, and I was able to fix it by upgrading that. I solved the problem by copying relevant sections from the JUnit5 sample Maven project on Github:

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>5.5.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>
    </plugins>
</build>

这篇关于Maven默默地找不到要运行的JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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