当前位置:网站首页>SSM framework series - JUnit unit test optimization day2-3
SSM framework series - JUnit unit test optimization day2-3
2022-04-23 12:42:00 【Concise programming】
SSM Frame series ——Junit Unit test optimization
Junit
brief introduction (from baidu)
JUnit It's a Java The language's unit testing framework . It consists of Kent Beck and Erich Gamma establish , Gradually become from Kent Beck Of sUnit Of xUnit The most successful one in the family . JUnit It has its own JUnit Expand the ecosystem . Most of the Java The development environment of has been integrated JUnit As a tool for unit testing
JUnit By Erich Gamma and Kent Beck Write a regression testing framework (regression testing framework).Junit Testing is programmer testing , The so-called white box test , Because programmers know how the software being tested (How) How to complete the function and what to complete (What) The function of .Junit It's a framework , Inherit TestCase class , You can use it Junit It's automated
Junit5 Can't use @RunWith
If you used the previous Spring In the version, everyone is doing junit Unit tests will be used @RunWith Appoint Spring Kernel testing , however Spring5 After use junit There is no such annotation
reason
It's actually Spring Support Junit5, stay 5 There is no such annotation in. It has been integrated, so it doesn't need to be used anymore @RunWith()
@RunWith The functions of are @ExtendWith replace , The original @RunWith(SpringRunner.class) By the same function @ExtendWith(SpringExtension.class) replace . but JUnit5 in @SpringBootTest The annotation already contains... By default @ExtendWith(SpringExtension.class).
So Spring Can only be used in Spring4
Because the version corresponds to @ExtendWith(SpringJUnit4ClassRunner.class)
I won't write code for you here
See my article on unit testing :SpringBoot—— unit testing
But if you reduce the version to use Junit4 To test, I give the following simple example
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;
// Specifies the kernel to use
@RunWith(SpringJUnit4ClassRunner.class)
//@ExtendWith(SpringJUnit4ClassRunner.class)
// Indicates the configuration context
@ContextConfiguration(classes = {
TestConfiguation.class})
public class TestBetter {
// Automatic injection
@Autowired
private TestService testService;
@Test
public void testServiceTest(){
this.testService.testShow();
}
}
版权声明
本文为[Concise programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231239441816.html
边栏推荐
- [unity note] basic lighting in l4unity
- BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此
- 没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
- QT double buffer drawing
- 网站首页文件被攻击篡改的形式有哪些
- flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
- S2-062 remote command execution vulnerability recurrence (cve-2021-31805)
- Zero trust in network information security
- 风尚云网学习-input属性总结
- 如何防止网站被黑客入侵篡改
猜你喜欢
Analysis of InnoDB execution process in MySQL
SQL exercise (I)
Qt进程间通信
Bert base Chinese Download (SMART)
4.DRF 权限&访问频率&过滤&排序
Aviation core technology sharing | overview of safety characteristics of acm32 MCU
I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
SSM框架系列——注解开发day2-2
免费试用一个月的服务器,并附上教程
标签与路径
随机推荐
Kubernetes 入门教程
NPDP|产品经理如何做到不会被程序员排斥?
BaseRecyclerViewAdapterHelper 实现下拉刷新和上拉加载
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
Redis deployment of cloud native kubesphere
S2-062 远程命令执行漏洞复现(cve-2021-31805)
Uni app native app local packaging integrated Aurora push (jg-jpush) detailed tutorial
C set Logo Icon and shortcut icon
How to prevent the website from being hacked and tampered with
Lesson 23 temporary objects
AD20补充笔记3—快捷键+持续更新
栈和队列a
[unity note] basic lighting in l4unity
Plato farm - a game of farm metauniverse with Plato as the goal
0基础可以考CPDA数据分析师证书吗
[daily question] chessboard question
C#,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码
风尚云网学习-input属性总结
网络信息安全之零信任
21 天学习MongoDB笔记