将JUnit 5测试结果与Intellij测试报告集成 [英] Integrate JUnit 5 tests results with Intellij test report

查看:1334
本文介绍了将JUnit 5测试结果与Intellij测试报告集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的build.gradle配置如下:

My build.gradle is configure like this:

apply plugin: 'java'

compileTestJava {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}

repositories {
    mavenCentral()
}

dependencies {
    testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0-M1")
    testRuntime("org.junit.vintage:junit-vintage-engine:5.0.0-M1")
}

和这样的简单测试:

public class JUnit5Test {
    @Test
    void test() {

    }
}

当我执行测试时,我在控制台中看到了这一点:

When I execute my test, I see this in the console:

Test run finished after 76 ms
[         1 tests found     ]
[         0 tests skipped   ]
[         1 tests started   ]
[         0 tests aborted   ]
[         1 tests successful]
[         0 tests failed    ]

BUILD SUCCESSFUL

但测试报告中没有任何内容:

But there's nothing in the test report:

我做错了什么?如何将JUnit 5结果集成到测试报告窗口中?

What do I do wrong? How can I integrate JUnit 5 results into the test report windows ?

我正在使用Intellij 2016.2

I'm using Intellij 2016.2

推荐答案

从版本2016.2开始,这是完全支持。它就像使用junit4测试结果一样工作:你需要激活JUnit插件(参见文件菜单,设置..项目,插件部分)。

As of version 2016.2 this is now fully supported. It works just like it does with junit4 test results: you do need the JUnit plugin activated (see under File menu, Settings.. item, Plugins section).

Don'使用Gradle工具窗口开始测试,直接使用IDE工具。其中包括:

Don't use the Gradle tool window to start your test, use the IDE tools directly. These include:


  • 点击边距图标(看起来像一个叠加了小播放图标的绿色圆圈)并选择运行或Debug

  • 右键单击类或方法名称并选择运行或调试

  • 使用运行菜单,任何带有运行或调试的菜单项

  • 在运行配置工具栏下拉列表中选择测试类,然后单击绿色的播放图标。

  • Clicking the margin icon (looks like a green circle with a small "play" icon superimposed) and selecting "Run" or "Debug"
  • Right-clicking the class or method name and selecting "Run" or "Debug"
  • Using the "Run" menu, any menu item with "Run" or "Debug"
  • Selecting the test class in the run configuration toolbar dropdown, then clicking the green "Play" icon.

请注意,目前, @TestFactory 方法不能以这种方式运行。如果您只有 @TestFactory 方法的课程,这可能会非常令人困惑!您可以通过向包含 @TestFactory 方法的类添加虚拟 @Test 方法来解决此问题,然后将该类作为如上所述。运行整个类时,可以正确找到 @TestFactory 方法。

Note that currently, @TestFactory methods cannot be run this way. This can be very confusing if you've got classes with only @TestFactory methods! You can work around this by adding a dummy @Test method to classes containing @TestFactory methods, then run the class as described above. The @TestFactory methods are found correctly when the entire class is run.

这篇关于将JUnit 5测试结果与Intellij测试报告集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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