当前位置:网站首页>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
边栏推荐
- 解决disagrees about version of symbol device_create
- 如何防止网站被黑客入侵篡改
- Pre competition practice of TIANTI competition
- 消息队列概述
- Basic software testing Day2 - Case Execution
- Why is the premise of hash% length = = hash & (length-1) that length is the nth power of 2
- Use source insight to view and edit source code
- Everything can be expected in the future | one 2022 campus recruitment officially opened
- Outsourcing for five years, abandoned
- Metalama简介4.使用Fabric操作项目或命名空间
猜你喜欢
NPDP|产品经理如何做到不会被程序员排斥?
Pagoda panel command line help tutorial (including resetting password)
Plato farm - a game of farm metauniverse with Plato as the goal
XinChaCha Trust SSL Organization Validated
Qt一个进程运行另一个进程
如何防止网站被黑客入侵篡改
【每日一题】棋盘问题
网站首页文件被攻击篡改的形式有哪些
A graphic designer's fantasy world | ones characters
在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决
随机推荐
Introduction to metalama 4 Use fabric to manipulate items or namespaces
STM32CubeProgrammer基础使用说明
leetcode:437. Path sum III [DFS selected or not selected?]
电脑系统卡如何解决?
对话PostgreSQL作者Bruce:“转行”是为了更好地前行
Everything can be expected in the future | one 2022 campus recruitment officially opened
云原生KubeSphere部署Mysql
【每日一题】棋盘问题
Worder font page font comparison table
box-sizing
Kubernetes 入门教程
没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
How to solve the computer system card?
风尚云网学习-input属性总结
4.DRF 权限&访问频率&过滤&排序
SQLserver怎么插入或更新当天的星期数,bit而不是文本
SSL证书退款说明
Fashion cloud learning - input attribute summary
Zero trust in network information security
S2-062 remote command execution vulnerability recurrence (cve-2021-31805)