当前位置:网站首页>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
边栏推荐
- SQLserver怎么插入或更新当天的星期数,bit而不是文本
- 没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
- box-sizing
- Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial
- AI video cloud vs narrowband HD, who is the darling of the video era
- 31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...
- 对话PostgreSQL作者Bruce:“转行”是为了更好地前行
- XinChaCha Trust SSL Organization Validated
- 甲辰篇 創世紀《「內元宇宙」聯載》
- Plato farm - a game of farm metauniverse with Plato as the goal
猜你喜欢

I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings

风尚云网学习-input属性总结

QT double buffer drawing

Recommended programming AIDS: picture tool snipaste

如何防止网站被黑客入侵篡改

云原生KubeSphere部署Mysql

0基础可以考CPDA数据分析师证书吗

c# 设置logo图标和快捷方式的图标

Zigbee之CC2530最小系统及寄存器配置(1)

A graphic designer's fantasy world | ones characters
随机推荐
实现一个盒子在父盒子中水平垂直居中的几种“姿势”
【csnote】ER图
mysql中 innoDB执行过程分析
Stm32cubeprogrammer basic instructions
How to switch PHP version in Windows 2008 system
Plato Farm-以柏拉图为目标的农场元宇宙游戏
在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决
C set Logo Icon and shortcut icon
QT redraw events and cuts
Why is the premise of hash% length = = hash & (length-1) that length is the nth power of 2
[daily question] chessboard question
Worder font page font comparison table
洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
SSL证书退款说明
STM32工程移植:不同型号芯片工程之间的移植:ZE到C8
BaseRecyclerViewAdapterHelper 实现下拉刷新和上拉加载
Labels and paths
How to solve the computer system card?
Markdown语法学习
One way ANOVA of SPSS