当前位置:网站首页>Section 2: spingboot unit test
Section 2: spingboot unit test
2022-06-23 04:05:00 【Introductory notes】
Generally, after we write a function , Will use the test data , Verify that our code can output the expected value . Unit tests will be used at this time .SpingBoot The government has provided us with spring-boot-starter-test Test components .
On the basis of the previous section pom.xml Introduce dependencies
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency>
- test Create the test class in the directory
- establish
com.rumenz.lession2.HelloWorldTest2HelloWorldfile
Method 1
Use
@SpringBootTestand@AutoConfigureMockMvcannotation .com.rumenz.lession2.HelloWorldTestHelloWorld
HelloWorldTestHelloWorld.java
@SpringBootTest
@AutoConfigureMockMvc
public class HelloWorldTestHelloWorld {
@Autowired
private MockMvc mockMvc;
@Test
public void testHelloWorld() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.get("/")).andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string(Matchers.containsString(" Entry station ")));
}
}Method 2
Use
@WebMvcTestannotation ,com.rumenz.lession2.HelloWorldTest2HelloWorld
/**
* @className: HelloWorldTestHelloWorld
* @description: TODO Class description
* @author: Entry station rumenz.com WeChat official account : Entry station
* @date: 2021/10/31
**/
@WebMvcTest
public class HelloWorldTest2HelloWorld {
@Autowired
private MockMvc mockMvc;
@Test
public void testHelloWorld() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.get("/")).andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string(Matchers.containsString(" Entry station ")));
}
}Run the test
stay @Test Right click the annotation ,
Run 'testHelloWorld()' with 'Allocation Profiler'
test result
The source code address of this summary :
边栏推荐
- Banknext microservice: a case study
- HAProxy的编译安装及全局配置段说明
- Web page dynamic and static separation based on haproxy
- Tcapulusdb Jun · industry news collection (III)
- For patch rollback, please check the cbpersistent log
- mysql存储引擎之Myisam和Innodb的区别
- SwiftUI 组件大全之使用 ScrollView 和 GeometryReader 创建动画 3D卡片 滚动效果
- Engineer culture: should the company buy genuine software
- JS array de duplication, removing the same value
- 基于HAProxy实现网页动静分离
猜你喜欢

Fetch request details

基于HAProxy实现网页动静分离

How to process large volume xlsx/csv/txt files?

软件项目管理 8.4.软件项目质量计划

HAProxy的编译安装及全局配置段说明
![[Zeng shuge's laser slam notes] gmapping filter based slam](/img/93/b940ad95508d1c0d23642022df37f2.png)
[Zeng shuge's laser slam notes] gmapping filter based slam

Talk about memory model and memory order

innodb_ruby 视角下 MySQL 记录增删改
![[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation](/img/eb/0d4caf0babbe14f51f4dbf1b9ae65d.png)
[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation

Google Earth Engine(GEE)——长时间序列逐月VCI数据提取分析和面积计算(墨西哥为例)
随机推荐
[tcapulusdb knowledge base] [list table] delete all data sample codes in the list
Is LinkedList a one-way linked list or a two-way linked list?
【LeetCode】翻转链表II
冒泡排序法
AI 视频云 VS 窄带高清,谁是视频时代的宠儿
MySQL optimization, the SQL execution is very stuck, and the SQL structure will not be changed until it ends in 10 seconds
[tcapulusdb knowledge base] [list table] sample code for inserting data into the specified position in the list
Banknext microservice: a case study
Adobe international certification 𞓜 how IIT Madras brings efficiency and accessibility to scholars through Adobe e Acrobat
What is the difference between ArrayList and LinkedList?
For patch rollback, please check the cbpersistent log
Summary of some precautions and problems in the use of tars framework (mengxinxiang)
[binary tree] 993 Cousins in Binary Tree
AI video cloud vs narrowband HD, who is the favorite in the video Era
The power of code refactoring: how to measure the success of refactoring
1-1VMware介绍
【LeetCode】179. Maximum number
Questions about SQL statements
直接插入排序
APM 工具 SkyWalking 是什么