JUnit 5-使用JUnit Jupiter引擎时,IntelliJ IDEA中的测试套件为空

戴维地斯:

如何在IntelliJ IDEA v2016.2.2中使用JUnit 5执行所有Suite测试?

我得到运行此代码的Empty测试套件

import org.junit.platform.runner.IncludeEngines;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.runner.SelectPackages;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
@IncludeEngines("junit-jupiter")
@SelectPackages("<eu...package>") //I confirm that <eu...package> is ok.
public class AllTests {
}

我收到:

INFORMAZIONI: Discovered TestEngines with IDs: [junit-jupiter, junit-vintage]
Empty test suite.
Empty test suite.

[root]
JUnit Jupiter
JUnit Vintage

要么

import eu.....services.ServiceTest;
import eu.....repository.DAOTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({
        ServiceTest.class,
        DAOTest.class
})
public class AllTests {
}

我收到:

INFORMAZIONI: Discovered TestEngines with IDs: [junit-jupiter, junit-vintage]
Empty test suite.

[root]
|+--JUnit Vintage
|   +--eu.....AllTests
|+--JUnit Jupiter

我能够在JUnit 4上运行套件,但不适用于JUnit 5。

山姆·布兰嫩:

简短答案

如果使用的是IntelliJ IDEA 2016.2,则当前无法@RunWith(JUnitPlatform.class)在IDE中执行带注释的测试类

长答案

根据您报告的行为,经过一些艰苦的调查工作,我相信我可以回答您的问题...

如果您使用的是IntelliJ IDEA 2016.2,它内置了对JUnit 5的支持,那么正在发生以下情况。

  1. IDEA通过LauncherAPI 启动JUnit Platform ,选择带有注释的测试类@RunWith(JUnitPlatform.class)(我们称之为TestSuite)。
  2. 同时Launcher检测junit-jupiterjunit-vintage TestEngine实现。
  3. JUnit Jupiter引擎将忽略TestSuite它,因为从技术上讲,它不是JUnit Jupiter测试类。
  4. 由于JUnit Vintage引擎TestSuite带有注释,因此也将忽略@RunWith(JUnitPlatform.class)
  5. 最终结果是没有注册的测试引擎声称它可以运行TestSuite该类。

不直观的部分是JUnit Vintage引擎会忽略TestSuite,因为它实际上是基于JUnit 4的测试类,因为它带有注释@RunWith()被忽略的原因是为了避免无限递归,在DefensiveAllDefaultPossibilitiesBuilder的源代码中对此进行了解释

if ("org.junit.platform.runner.JUnitPlatform".equals(runnerClass.getName())) {
    return null;
}

上面的代码null在这种情况下返回的事实导致一个空套件

当然,如果将这样的情况通知用户(例如通过log语句)肯定会更好。因此,我为JUnit 5IntelliJ打开了问题,以改善这种情况下的可用性。

从好的方面来说,由于您使用的是IntelliJ IDEA 2016.2,因此不需要使用测试套件支持。相反,您只需src/test/java在IDEA的项目视图中右键单击并选择Run 'All Tests',这将运行所有测试。

问候,

Sam (JUnit 5核心提交者)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何测试JUnit Jupiter(JUnit 5)扩展

如何使用Jupiter Junit5平台的老式引擎通过gradle配置按类别运行JUnit4测试

JUnit Jupiter(JUnit5)中的参数化测试执行

在 IntelliJ Idea 中无法识别 JUnit 5 测试

找不到测试-在裸骨Spring Boot Maven项目上运行jUnit 5测试用例时,测试套件为空

在IntelliJ中运行TestCase时,为什么JUnit Jupiter和JUnit Vintage分开?

使用MockMvc和JUnit 5测试LocalDate时出现AssertionError

如何在JUnit5中为测试套件设置自定义测试执行顺序?

使用IntelliJ IDEA设置JUnit

使用IntelliJ运行JUnit测试

使用IntelliJ创建Junit测试

JUnit 5测试套件选择测试方法

IntelliJ + JUnit 5(木星)

Junit 5和IntelliJ“未找到测试”

无法从IntelliJ IDEA运行JUnit-5测试用例

被测试套件中JUnit5考虑废弃?

IntelliJ不会自动完成JUnit 5 Jupiter类

如何使用junit 5订购测试

测试的预期异常消息使用JUnit 5

使用JUnit 5时Powermock抛出ClassNotPreparedException

Junit测试5(异常)

JUnit 5测试

Junit 5测试toString()

在JUnit 5 Jupiter中使用两个参数进行参数化测试

尝试使用Maven运行Mockito junit5测试时,java.lang.NoClassDefFoundError:org / junit / platform / commons / PreconditionViolationException

尝试使用junit5和mockito模拟byte []值时为空值

使用Spring Boot和JUnit5在Intellij中终止所有测试

Netbeans 中的 JUnit 5 测试

如何使用 junit 5 (Jupiter) 模拟 RestTemplate 交换