SpringBoot单元测试编译报错Norunnablemethods
我看到好多情况都是这样的:
参考:
遇到这种情况表⽰单元测试中没有可以运⾏的⽅法,有可能是以下的原因:
1.第⼀种情况,有的测试类为空,只定义了⼀个类名,也就是类⾥⾯没有能运⾏的⽅法
2.第⼆种情况,测试类⽅法有错,或者没有添加@Test注解。
然⽽这些⽅法好像都没有解决我的问题,⾃⾏测试时,测试如下修改,有效,好像是junit版本问题。
import org.junit.jupiter.api.Test;
# 将上⾯这⾏改成下⾯的即可。
import org.junit.Test;
spring boot 2.2 之前使⽤的是 Junit4 ⽽后续的使⽤的是Junit5
springboot是啥注解说明:
org.junit.jupiter.api.Test
@Test is used to signal that the annotated method is a test method.
@Test methods must not be private or staticand must not return a value.
@Test methods may optionally declare parameters to beresolved by ParameterResolvers.
@Test may also be used as a meta-annotation in order to createa custom composed annotation that inherits the semantics of @Test.
org.junit.Test
The Test annotation tells JUnit that the public void methodto which it is attached can be run as a test case. To run the method,JUnit first constructs a fresh instance of the class then invokes theannotated method. Any exceptions thrown by the test will be reportedby JUnit as a failure. If no exceptions are thrown , the test is assumedto have succeeded.
我没看出啥区别。有位博客讲得听清楚的,但是我的运⾏不了……

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。