【问题标题】:Create TestSuite in JUnit5 (Eclipse)在 JUnit5 (Eclipse) 中创建 TestSuite
【发布时间】:2018-11-02 06:20:37
【问题描述】:

我在eclipse中创建了多个测试用例java文件,JUnit的版本是JUnit5。

现在,我正在尝试通过 Eclipse GUI 创建一个 Junit TestSuite,在创建过程中,我没有看到可用版本中的 JUnit5。

这是我为创建 TestSuite 编写的示例代码。

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.IncludeClassNamePatterns;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
@IncludeClassNamePatterns(".*Tests?")
@IncludeEngines("junit-jupiter")

public class AllTests {
}

这是我在执行时遇到的错误。

我是否应该进行任何手动设置才能创建/运行测试套件?

【问题讨论】:

    标签: java unit-testing junit5


    【解决方案1】:

    在使用 @RunWith 注释的类中执行测试时,该类在技术上是 JUnit 4 测试类。

    因此,您必须使用 Eclipse 的“运行配置”中的“JUnit 4 Runner”来执行您的测试套件。

    有关更多信息,请参阅以下 Eclipse 错误:https://bugs.eclipse.org/bugs/show_bug.cgi?id=512772

    关于“JUnit 测试套件”对话框,如果您使用 @RunWith(JUnitPlatform.class) 在 JUnit 5 中执行套件,这对您没有帮助。

    【讨论】:

    • 那么在 JUnit5 中创建测试套件的方法是什么?
    • 如果您使用的是@RunWith(JUnitPlatform.class),这在技术上是 JUnit 5 中的一个套件。只是它使用 JUnit 4 来启动 JUnit 5 平台。
    • 但是请注意,我们计划为不需要 JUnit 4 Runner 的 JUnit 5 中的套件提供一流的支持。有关详细信息,请参阅 GitHub 中所有标有 suite 的问题:github.com/junit-team/junit5/…
    【解决方案2】:

    你没有使用 JUnit5,Junit5 FQN 是 org.junit.jupiter.api.*

    https://www.eclipse.org/community/eclipse_newsletter/2017/october/article5.php

    【讨论】:

      猜你喜欢
      • 2015-05-08
      • 2015-05-10
      • 1970-01-01
      • 2021-04-19
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      相关资源
      最近更新 更多