我看到好多情况都是这样的:
参考:https://blog.csdn.net/u010429286/article/details/53520810
遇到这种情况表示单元测试中没有可以运行的方法,有可能是以下的原因:
1.第一种情况,有的测试类为空,只定义了一个类名,也就是类里面没有能运行的方法
2.第二种情况,测试类方法有错,或者没有添加@Test注解。
然而这些方法好像都没有解决我的问题,自行测试时,测试如下修改,有效,好像是junit版本问题。
import org.junit.jupiter.api.Test;
# 将上面这行改成下面的即可。
import org.junit.Test;
spring boot 2.2 之前使用的是 Junit4 而后续的使用的是Junit5
注解说明:
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.
我没看出啥区别。有位博客讲得听清楚的,但是我的运行不了……
Spring Boot 2.2.x Junit4 升级为Junit5 后的变化、对比 找不到 org.junit.jupiter.api.Test