Springboot测试类的编写
1.首先看看Controller写的一些东西
@RestController
public class HelloController {@RequestMapping("/hello")public String hello() {return "hello world!";}
}
2.现在来看看测试类的编写方式
package com.example.demo.weather.controller;import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;/*** * @author qushen**/
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerTest {@Autowiredprivate MockMvc mocmvc;@Testpublic void TestHello() throws Exception {mocmvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(equalTo("hello world!")));}
}
Springboot测试类的编写相关推荐
- 天呐!惊人的Springboot测试.Springboot测试类之@RunWith注解
Springboot测试类之@RunWith注解 Springboot测试类之@RunWith注解 Springboot测试类之@RunWith注解 @runWith注解作用: @RunWith就是一 ...
- SpringBoot 使用junit 进行测试类的编写
SpringBoot 是最近比较火的一个框架,他几乎把Spring 对框架的整合简化的只需要动动手指就可以实现,spring Boot 把配置的Xml 去掉啦,只是用啦一个 application.p ...
- SpringBoot测试类不需要加@RunWith?
# 在idea中,自动生成的测试类没有@RunWith运行正常? 在SpringBoot2.2.0以前是JUnit4,在SpringBoot之后是JUnit5. Juint版本说明 Junit4 &l ...
- springboot(测试类)整合mybatisplus增删改查
文章目录 下载地址 1.创建springboot项目(Spring Initializer快速创建) 2.配置文件,数据库等 3.配置,策略,实体类 4.增删改查 查询 查询全部 查询-根据id批量查 ...
- Springboot测试类之@RunWith注解
@runWith注解作用: --@RunWith就是一个运行器 --@RunWith(JUnit4.class)就是指用JUnit4来运行 --@RunWith(SpringJUnit4ClassRu ...
- XCode中的单元测试:编写测试类和方法(内容意译自苹果官方文档)
当你在工程中通过测试导航栏添加了一个测试target之后, xcode会在测试导航栏中显示该target所属的测试类和方法. 这一章演示了怎么创建测试类,以及如何编写测试方法. 测试targets, ...
- spring、springboot项目测试类遇到的问题
常见问题: 1.junit注解无法使用 junit依赖中添加了<scope>test</scope>junit中的注解需要在项目中src下的test文件夹(如删了或没有需要自己 ...
- springboot集成Junit在执行测试类的时候提示Failed to resolve异常
项目场景:springboot集成Junit在执行测试类的时候提示Failed to resolve异常 项目场景:springboot版本2.5.7,Junit版本:4.13.2,在执行测试类的时候 ...
- 定义一个 圆形 Circle类 , 定义其中的长度length属性,定义一个求面积getArea()的方法。 并编写一个测试类,进行长度的赋值和展示,并调用求面积方法展示面积值。
定义一个 圆形 Circle类 , 定义其中的长度length属性,定义一个求面积getArea()的方法. 并编写一个测试类,进行长度的赋值和展示,并调用求面积方法展示面积值. public cla ...
最新文章
- リストに項番をつける
- [device]/proc/devices and /dev/
- 如何安装fedora13的显卡驱动
- VMware LUN发现、日志、操作
- spring boot二:搭建环境
- 深度学习之基于Inception_ResNet_V2和CNN实现交通标志识别
- iOS项目开发— CoreLocation的定位服务和地理编码与发编码实现
- bool类型数组转换成一个整数_Go 学习笔记 02 | 基本数据类型以及 byte 和 rune 类型...
- MyFlash使用总结
- 今天买到了回家的火车票,有座儿,心情不错.
- Ubuntu下的QQ-For-Linux 安装
- dosbox运行C语言,DOSBox怎么用?DOSBox使用教程
- 华为 C/C++ 编程规范(精华总结)
- CSS与CSS3美化页面
- c语言小车路径规划算法,基于路径规划的室内小车定位系统
- 国庆促销海报模板素材
- Windows64位 python3.6安装pyHook
- mysql判断当前日期是否为节假日_java 判断日期是否是节假日
- 成为成功的软件开发顾问的5个关键
- 【Linux】Linux运维命令汇总单词表