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测试类的编写相关推荐

  1. 天呐!惊人的Springboot测试.Springboot测试类之@RunWith注解

    Springboot测试类之@RunWith注解 Springboot测试类之@RunWith注解 Springboot测试类之@RunWith注解 @runWith注解作用: @RunWith就是一 ...

  2. SpringBoot 使用junit 进行测试类的编写

    SpringBoot 是最近比较火的一个框架,他几乎把Spring 对框架的整合简化的只需要动动手指就可以实现,spring Boot 把配置的Xml 去掉啦,只是用啦一个 application.p ...

  3. SpringBoot测试类不需要加@RunWith?

    # 在idea中,自动生成的测试类没有@RunWith运行正常? 在SpringBoot2.2.0以前是JUnit4,在SpringBoot之后是JUnit5. Juint版本说明 Junit4 &l ...

  4. springboot(测试类)整合mybatisplus增删改查

    文章目录 下载地址 1.创建springboot项目(Spring Initializer快速创建) 2.配置文件,数据库等 3.配置,策略,实体类 4.增删改查 查询 查询全部 查询-根据id批量查 ...

  5. Springboot测试类之@RunWith注解

    @runWith注解作用: --@RunWith就是一个运行器 --@RunWith(JUnit4.class)就是指用JUnit4来运行 --@RunWith(SpringJUnit4ClassRu ...

  6. XCode中的单元测试:编写测试类和方法(内容意译自苹果官方文档)

    当你在工程中通过测试导航栏添加了一个测试target之后, xcode会在测试导航栏中显示该target所属的测试类和方法. 这一章演示了怎么创建测试类,以及如何编写测试方法. 测试targets, ...

  7. spring、springboot项目测试类遇到的问题

    常见问题: 1.junit注解无法使用 junit依赖中添加了<scope>test</scope>junit中的注解需要在项目中src下的test文件夹(如删了或没有需要自己 ...

  8. springboot集成Junit在执行测试类的时候提示Failed to resolve异常

    项目场景:springboot集成Junit在执行测试类的时候提示Failed to resolve异常 项目场景:springboot版本2.5.7,Junit版本:4.13.2,在执行测试类的时候 ...

  9. 定义一个 圆形 Circle类 , 定义其中的长度length属性,定义一个求面积getArea()的方法。 并编写一个测试类,进行长度的赋值和展示,并调用求面积方法展示面积值。

    定义一个 圆形 Circle类 , 定义其中的长度length属性,定义一个求面积getArea()的方法. 并编写一个测试类,进行长度的赋值和展示,并调用求面积方法展示面积值. public cla ...

最新文章

  1. リストに項番をつける
  2. [device]/proc/devices and /dev/
  3. 如何安装fedora13的显卡驱动
  4. VMware LUN发现、日志、操作
  5. spring boot二:搭建环境
  6. 深度学习之基于Inception_ResNet_V2和CNN实现交通标志识别
  7. iOS项目开发— CoreLocation的定位服务和地理编码与发编码实现
  8. bool类型数组转换成一个整数_Go 学习笔记 02 | 基本数据类型以及 byte 和 rune 类型...
  9. MyFlash使用总结
  10. 今天买到了回家的火车票,有座儿,心情不错.
  11. Ubuntu下的QQ-For-Linux 安装
  12. dosbox运行C语言,DOSBox怎么用?DOSBox使用教程
  13. 华为 C/C++ 编程规范(精华总结)
  14. CSS与CSS3美化页面
  15. c语言小车路径规划算法,基于路径规划的室内小车定位系统
  16. 国庆促销海报模板素材
  17. Windows64位 python3.6安装pyHook
  18. mysql判断当前日期是否为节假日_java 判断日期是否是节假日
  19. 成为成功的软件开发顾问的5个关键
  20. 【Linux】Linux运维命令汇总单词表

热门文章

  1. 打破“创新困局”,让你的企业创意盎然的六个新角色
  2. RxJS Functional Programming
  3. Spring事务处理,以及Spring事务的传播属性和隔离级别
  4. Asp.net禁用site.Mobile.Master
  5. linux系统安装细节及磁盘分区划分
  6. tyvj1102 单词的划分
  7. 关于JSON的简介及取值以及常见面试题
  8. Android学习笔记四十Preference使用
  9. jQuery获取自身HTML
  10. php curl 获取 邮箱通讯录 sns(hotmail)