gpt4 book ai didi

eclipse - 如何使用 junit 5 为 eclipse 编写测试套件?

转载 作者:行者123 更新时间:2023-12-05 04:53:31 26 4
gpt4 key购买 nike

我正在尝试通过测试套件中的 junit5 测试运行。但是我得到一个错误

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.runner.RunWith;

import com.test.studentservice.controllers.StudentControllerTest2;
import com.test.studentservice.repo.StudentServiceRepoDataTest;
import com.test.studentservice.service.StudentServiceTest;

@RunWith(JUnitPlatform.class)
@SelectClasses({StudentControllerTest2.class, StudentServiceRepoDataTest.class, StudentServiceTest.class})
public class StudentServiceTestSuite {

}

这是我遇到的错误: this is the error im getting

谢谢

最佳答案

您会收到此错误,因为在 JUnit 启动配置(运行 > 运行配置...)的测试 选项卡中,您选择 Test runner JUnit 5 而不是 JUnit 4

@RunWith(JUnitPlatform.class) 用于将 JUnit 5 测试作为 JUnit 4 测试运行,以防工具仅支持 JUnit 4 但不支持 JUnit 5 ( for details see this answer )。但是您不需要它,因为 Eclipse 支持 JUnit 5 并且不应该使用它,因为通过 JUnit 4 API 运行它有一些限制。

Baeldung - A Guide to JUnit 5 - 7. Test Suites哪个you mentioned in a comment you are following here , 在这一点上是错误的,或者至少是误导性的。代替 JUnit 测试套件类,标记您的测试并使用它们来包含或排除测试(在 JUnit 启动配置中,在 Test 选项卡中,点击 Configure... 按钮)。

关于eclipse - 如何使用 junit 5 为 eclipse 编写测试套件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66022322/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com