spring boot与junit集成测试
先创建一个REST接口
package com.laoxu.gamedog.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author xusucheng
* @create 2018-12-14
**/
@RestController
@RequestMapping("/hello")
public class HelloController {
@RequestMapping("/")
public String sayHello(@RequestParam("name") String name){
return "Hello "+name+"!";
}
}
创建对应单元测试类
package com.laoxu.gamedog;
import com.laoxu.gamedog.controller.HelloController;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
/**
* @author xusucheng
* @create 2018-12-14
**/
@RunWith(SpringRunner.class)
@SpringBootTest
public class HelloControllerTest {
@Autowired
private HelloController helloController;
@Test
public void testHello(){
String result = helloController.sayHello("Jack");
assertEquals("Hello Jack!",result);
}
}
运行结果

spring boot与junit集成测试的更多相关文章
- Spring Boot 解决方案 - JUnit 测试
简单的 JUnit 项目 回顾一下创建并运行简单的 JUnit 测试项目,先添加 JUnit 依赖然后编写类似如下模板的测试类,使用 IDE 的话直接用插件运行就行, 使用 Maven 的话运行命令 ...
- Spring Boot 整合Junit和redis
14. Spring Boot整合-Junit 目标:在Spring Boot项目中使用Junit进行单元测试UserService的方法 分析: 添加启动器依赖spring-boot-starter ...
- Spring Boot WebFlux-09——WebFlux 集成测试及部署
第09课:WebFlux 集成测试及部署 前言 在日常工作中,免不了自测 UT,因为覆盖率不达标,是不允许提交测试,那怎么进行 WebFlux 项目的测试呢.@WebFluxTest 是 WebFlu ...
- Spring Boot 测试 junit
import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.ann ...
- spring boot使用TestRestTemplate集成测试 RESTful 接口
这篇文章没什么技术含量,只是单纯的记录一下如何用TestRestTemplate访问受security保护的api,供以后查阅. @Slf4j @RunWith(SpringRunner.class) ...
- Spring Boot集成Junit测试
添加依赖: 在测试类上添加注解:
- Spring Boot 的单元测试和集成测试
学习如何使用本教程中提供的工具,并在 Spring Boot 环境中编写单元测试和集成测试. 1. 概览 本文中,我们将了解如何编写单元测试并将其集成在 Spring Boot 环境中.你可在网上找到 ...
- 为什么说 Java 程序员到了必须掌握 Spring Boot 的时候?
Spring Boot 2.0 的推出又激起了一阵学习 Spring Boot 热,就单从我个人的博客的访问量大幅增加就可以感受到大家对学习 Spring Boot 的热情,那么在这么多人热衷于学习 ...
- 为什么说Java程序员到了必须掌握Spring Boot的时候?
摘要: SpringBoot的来龙去脉. 原文:为什么说 Java 程序员到了必须掌握 Spring Boot 的时候? 微信公众号:纯洁的微笑 Fundebug经授权转载,版权归原作者所有. Spr ...
- 初识Spring Boot
1.Spring Boot简介 Spring Boot是由Pivotal团队提供的全新框架,用于简化基于Spring的搭建与开发过程,通过少量的代码创建Spring应用. 2.Spring Boo ...
随机推荐
- Hexo中引入另一个文件内容
有的时候博客内容会有变动,首发博客是最新的,其他博客地址可能会未同步,认准https://blog.zysicyj.top 首发博客地址 安装插件 npm install hexo-include-m ...
- [转帖]tcplife的使用
https://www.rutron.net/posts/2203/bcc-tcplife-usage/ 这篇文档主要演示了 tcplife(Linux eBPF/bcc) 工具的使用. 示例 tcp ...
- [转帖]性能优化:Swap调优
目标:解决大量Log写入占用大量的File Cache,内容利用不充分导致swap 基本原则:尽量使用内存,减少swap,同时,尽早flush到外存,早点释放内存给写cache使用.---特别在持续的 ...
- [转帖]LSM树详解
https://zhuanlan.zhihu.com/p/181498475 LSM树(Log-Structured-Merge-Tree)的名字往往会给初识者一个错误的印象,事实上,LSM树并不像B ...
- 【转帖】在ECS上配置skywalking-nginx-lua
https://help.aliyun.com/document_detail/197660.html 此处以在CentOS 7.0上的操作为例. 配置Lua运行环境. 安装工具库. yum in ...
- bean的一生
你曾读spring源码 "不知所云"."绞尽脑汁"."不知所措"嘛 那这篇文章可能会对你有所帮助,小编尝试用简单.易懂的例子来模拟sprin ...
- elementui出现展开后子菜单宽度多出1px问题
添加 就可以解决了 .el-menu { border-right-width: 0; } <template> <div class="compen-left-men&q ...
- Gin 应用多实例部署session问题、session参数与刷新
目录 一.Gin Session 存储的实现方案 二.memstore:基于内存的实现 2.1 基本使用 2.2 关键参数 三.使用redis:多实例部署 3.1 使用redis优势 3.2 基本使用 ...
- net core控制台程序使用依赖注入读取appsettings.json配置文件
.net 2.1有用,转自https://www.jianshu.com/p/726d1aa2795c 1.项目下添加appsettings.json文件,并将属性-复制到输出目录,设置为如果较新则复 ...
- 手撕Vue-Router-实现router-view
前言 在上一篇 [手撕Vue-Router-实现router-link] 中,我们实现了 router-link 组件,这一篇我们来实现 router-view 组件. 实现思路 router-vie ...