在JUnit5(Eclipse)中创建TestSuite [英] Create TestSuite in JUnit5 (Eclipse)

查看:68
本文介绍了在JUnit5(Eclipse)中创建TestSuite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Eclipse中创建了多个测试用例Java文件,并且JUnit的版本是JUnit5.

I have created multiple Test case java files in eclipse and version of JUnit is JUnit5.

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

Now, I am trying to create a Junit TestSuite through the eclipse GUI and during the creation, I am not seeing the JUnit5 in the available versions.

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

This is the sample code that I have written for creation of 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 {
}

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

This is the error I am getting while executing.

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

Should I do any manual setting to be able to create/run test suites?

推荐答案

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

When executing tests in a class annotated with @RunWith, that class is technically a JUnit 4 test class.

因此,您必须使用Eclipse运行配置"中的"JUnit 4 Runner"执行测试套件.

Thus, you have to execute your test suite using the "JUnit 4 Runner" in the "Run Configurations" of Eclipse.

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

See the following Eclipse bug for more information: https://bugs.eclipse.org/bugs/show_bug.cgi?id=512772

关于"JUnit测试套件"对话框,如果您正在使用 @RunWith(JUnitPlatform.class)在JUnit 5中执行套件,那将无济于事.

Regarding the "JUnit Test Suite" dialog, that won't help you if you are using @RunWith(JUnitPlatform.class) to execute a suite in JUnit 5.

这篇关于在JUnit5(Eclipse)中创建TestSuite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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