当前位置:网站首页>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
边栏推荐
- Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
- Bert base Chinese Download (SMART)
- uni-app 原生APP-本地打包集成极光推送(JG-JPUSH)详细教程
- I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
- 云原生KubeSphere部署Mysql
- 21 天学习MongoDB笔记
- 没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
- SSL certificate refund instructions
- QT double buffer drawing
- Labels and paths
猜你喜欢
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
SSM框架系列——注解开发day2-2
Deploying MySQL in cloud native kubesphere
Idea setting copyright information
ZigBee CC2530 minimum system and register configuration (1)
leetcode:437. 路径总和 III【dfs 选还是不选?】
How to prevent the website from being hacked and tampered with
Qt绘制图像
网络信息安全之零信任
Everything can be expected in the future | one 2022 campus recruitment officially opened
随机推荐
Qt绘制图像
Kubernetes 入门教程
Stm32cubeprogrammer basic instructions
大家帮我看一下这是啥情况,MySQL5.5的。谢了
Outsourcing for five years, abandoned
Deploying MySQL in cloud native kubesphere
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
对话PostgreSQL作者Bruce:“转行”是为了更好地前行
一个平面设计师的异想世界|ONES 人物
Metalama简介4.使用Fabric操作项目或命名空间
免费试用一个月的服务器,并附上教程
云原生KubeSphere部署Redis
BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此
Realize several "Postures" in which a box is horizontally and vertically centered in the parent box
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
Kubernetes 入門教程
Please help me see what this is, mysql5 5. Thanks
mysql中 innoDB执行过程分析
Why is the premise of hash% length = = hash & (length-1) that length is the nth power of 2
STM32工程移植:不同型号芯片工程之间的移植:ZE到C8