eclipse进行单元测试报错 已解决

eclipse进行单元测试报错 已解决,第1张

1. The class example.CalculatorTest is not public.

测试类要声明是public

2. Test class should have exactly one public constructor

在Junit测试类中必须声明一个public 构造函数,我的测试类没有声明public,默认为default 。

构建一个公有构造函数即可

3. No runnable methods

没有在方法上指定@Test,或者是@Test的包导错了

 @Test有两个包,将org.junit.jupiter.api.Test改为org.junit.Test

4. JUnit5中 @BeforeEach失效

JUnit5 @BeforeEach注解替换了 JUnit4 中的@Before注解。它用于表示应在当前类中的每个@Test方法之前执行注解方法。

但是我在运行过程中发现并没有在每个Test之前执行@BeforeEach,导入的包也是正确的。于是我把@BeforeEach改成了@Before,并导入 org.junit.Before,运行结果正确。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/723423.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存