Spring Boot单元测试编译报错 No runnable methods

我看到好多情况都是这样的:

参考: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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值