当前位置:网站首页>SSM框架系列——Junit单元测试优化day2-3
SSM框架系列——Junit单元测试优化day2-3
2022-04-23 12:39:00 【简明编程】
SSM框架系列——Junit单元测试优化
Junit
简介(from baidu)
JUnit是一个Java语言的单元测试框架。它由Kent Beck和Erich Gamma建立,逐渐成为源于Kent Beck的sUnit的xUnit家族中最为成功的一个。 JUnit有它自己的JUnit扩展生态圈。多数Java的开发环境都已经集成了JUnit作为单元测试的工具
JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework)。Junit测试是程序员测试,即所谓白盒测试,因为程序员知道被测试的软件如何(How)完成功能和完成什么样(What)的功能。Junit是一套框架,继承TestCase类,就可以用Junit进行自动测试了
Junit5无法使用@RunWith
如果用过之前的Spring版本的话大家在做junit单元测试的时候会使用@RunWith指定Spring内核进行测试,但是Spring5后使用junit已经没有了这个注解
原因
其实是Spring支持Junit5,在5中没有这个注解了已经被集成进去了所以不需要再用@RunWith()
@RunWith 的功能都被 @ExtendWith 替代,即原 @RunWith(SpringRunner.class) 被同功能的 @ExtendWith(SpringExtension.class) 替代。但 JUnit5 中 @SpringBootTest 注解中已经默认包含了 @ExtendWith(SpringExtension.class)。
所以说Spring中只能用Spring4
因为版本对应@ExtendWith(SpringJUnit4ClassRunner.class)
这里我就不给大家写代码了
有关单元测试的看我这篇:SpringBoot——单元测试
但如果你降低版本使用Junit4进行测试我给出以下测试简单示例
package com.exampl.junitTest;
import com.exampl.configuration.TestConfiguation;
import com.exampl.service.TestService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//指定使用内核
@RunWith(SpringJUnit4ClassRunner.class)
//@ExtendWith(SpringJUnit4ClassRunner.class)
//指明配置上下文
@ContextConfiguration(classes = {
TestConfiguation.class})
public class TestBetter {
//自动注入
@Autowired
private TestService testService;
@Test
public void testServiceTest(){
this.testService.testShow();
}
}
版权声明
本文为[简明编程]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_51553982/article/details/124358731
边栏推荐
- Qt绘制文字
- 天梯赛赛前练习
- 解决disagrees about version of symbol device_create
- Fashion cloud learning - input attribute summary
- Ad20 supplementary note 3 - shortcut key + continuous update
- Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years
- Everything can be expected in the future | one 2022 campus recruitment officially opened
- Unlock openharmony technology day! The annual event is about to open!
- C#,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码
- php生成json处理中文
猜你喜欢
天梯赛赛前练习
梳理网络IP代理的几大用途
NPDP|产品经理如何做到不会被程序员排斥?
Basic software testing Day2 - Case Execution
What are the forms of attack and tampering on the home page of the website
传统企业如何应对数字化转型?这些书给你答案
CGC: contractual graph clustering for community detection and tracking
Qt进程间通信
Kubernets Getting started tutoriel
对话PostgreSQL作者Bruce:“转行”是为了更好地前行
随机推荐
Remote sensing image classification and recognition system based on convolutional neural network
关于使用Go语言创建WebSocket服务浅谈
4.DRF 权限&访问频率&过滤&排序
解决disagrees about version of symbol device_create
BUUCTF WEB [BJDCTF2020]The mystery of ip
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
MySQL函数-递归函数
Pagoda panel command line help tutorial (including resetting password)
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
Lesson 23 temporary objects
Qt双缓冲绘图
SynchronousQueue 源码解析
风尚云网学习-h5的input:type属性的image属性
在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决
一个平面设计师的异想世界|ONES 人物
QT draw text
AD20补充笔记3—快捷键+持续更新
Markdown grammar learning
S2-062 remote command execution vulnerability recurrence (cve-2021-31805)
QT redraw events and cuts