我在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 {
}
这是我在执行时遇到的错误。
我应该进行任何手动设置才能创建/运行测试套件吗?
最佳答案
在用@RunWith
注释的类中执行测试时,该类从技术上讲是 JUnit 4 测试类。
因此,您必须使用 Eclipse 的“运行配置”中的“JUnit 4 Runner”来执行测试套件。
有关详细信息,请参阅以下 Eclipse 错误:https://bugs.eclipse.org/bugs/show_bug.cgi?id=512772
关于“JUnit Test Suite”对话框,如果您使用@RunWith(JUnitPlatform.class)
,这对您没有帮助。在 JUnit 5 中执行套件。
关于java - 在 JUnit5 (Eclipse) 中创建 TestSuite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50485339/