先创建一个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集成测试的更多相关文章

  1. Spring Boot 解决方案 - JUnit 测试

    简单的 JUnit 项目 回顾一下创建并运行简单的 JUnit 测试项目,先添加 JUnit 依赖然后编写类似如下模板的测试类,使用 IDE 的话直接用插件运行就行, 使用 Maven 的话运行命令 ...

  2. Spring Boot 整合Junit和redis

    14. Spring Boot整合-Junit 目标:在Spring Boot项目中使用Junit进行单元测试UserService的方法 分析: 添加启动器依赖spring-boot-starter ...

  3. Spring Boot WebFlux-09——WebFlux 集成测试及部署

    第09课:WebFlux 集成测试及部署 前言 在日常工作中,免不了自测 UT,因为覆盖率不达标,是不允许提交测试,那怎么进行 WebFlux 项目的测试呢.@WebFluxTest 是 WebFlu ...

  4. Spring Boot 测试 junit

    import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.ann ...

  5. spring boot使用TestRestTemplate集成测试 RESTful 接口

    这篇文章没什么技术含量,只是单纯的记录一下如何用TestRestTemplate访问受security保护的api,供以后查阅. @Slf4j @RunWith(SpringRunner.class) ...

  6. Spring Boot集成Junit测试

    添加依赖: 在测试类上添加注解:

  7. Spring Boot 的单元测试和集成测试

    学习如何使用本教程中提供的工具,并在 Spring Boot 环境中编写单元测试和集成测试. 1. 概览 本文中,我们将了解如何编写单元测试并将其集成在 Spring Boot 环境中.你可在网上找到 ...

  8. 为什么说 Java 程序员到了必须掌握 Spring Boot 的时候?

    Spring Boot 2.0 的推出又激起了一阵学习 Spring Boot 热,就单从我个人的博客的访问量大幅增加就可以感受到大家对学习 Spring Boot 的热情,那么在这么多人热衷于学习 ...

  9. 为什么说Java程序员到了必须掌握Spring Boot的时候?

    摘要: SpringBoot的来龙去脉. 原文:为什么说 Java 程序员到了必须掌握 Spring Boot 的时候? 微信公众号:纯洁的微笑 Fundebug经授权转载,版权归原作者所有. Spr ...

  10. 初识Spring Boot

    ​ 1.Spring Boot简介 Spring Boot是由Pivotal团队提供的全新框架,用于简化基于Spring的搭建与开发过程,通过少量的代码创建Spring应用. 2.Spring Boo ...

随机推荐

  1. [转帖]OceanBase 存储引擎详解

    https://zhuanlan.zhihu.com/p/436485359 作者简介:沈炼,蚂蚁集团技术风险部数据库高级专家毕业于东南大学,2014年以来从事 OceanBase 在蚂蚁的架构工作, ...

  2. [转帖]grafana自定义告警模版

     发表于 2022-03-16  更新于 2023-03-03 因 grafana 告警信息太多无用数据,容易干扰查看例如使用 企业微信告警消息如下太多无用Labels 例如 endpoint,job ...

  3. 常见的docker hub mirror镜像仓库

    阿里云(杭州) https://registry.cn-hangzhou.aliyuncs.com 阿里云(上海) https://registry.cn-shanghai.aliyuncs.com ...

  4. [转帖]Oracle JDBC中的语句缓存

    老熊 Oracle性能优化 2013-09-13 在Oracle数据库中,SQL解析有几种: 硬解析,过多的硬解析在系统中产生shared pool latch和library cache liatc ...

  5. 极简版 haproxy的搭建步骤

    背景 发现四层nginx的代理报错. 然后想着换用一下haproxy的配置. 早些时候 看过tidb的一些最佳时间, 这里简单整理一下. 下载 https://src.fedoraproject.or ...

  6. Jmeter学习之六_进行https证书处理的工作

    Jmeter 进行https证书处理的工作 背景 继续学习中,想着能够抓取一下https相关的信息 所以计划些一下处理过程 但是感觉自己这一块比较薄弱. 场景设计这一块应该是专业人去搞, 我这边先只是 ...

  7. [转帖]【jmeter】BeanShell用法详细汇总

    一.什么是Bean Shell BeanShell是用Java写成的,一个小型的.免费的.可以下载的.嵌入式的Java源代码解释器,具有对象脚本语言特性,非常精简的解释器jar文件大小为175k. B ...

  8. 多个物理磁盘挂载到同一目录的方法 (lvm 软raid)

    多个物理磁盘挂载到同一目录的方法 (lvm 软raid) 背景 公司里面的一台申威3231的机器 因为这个机器的raid卡没有操作界面. 所以只能够通过命令行方式创建raid 自己这一块比较菜, 想着 ...

  9. [转帖]Shell中常用的date时间命令

    常用FORMAT %Y  YYYY格式的年份(Year) %m  mm格式的月份(),01-12 %d   dd格式的日期(day of month),01-31 %H   HH格式的小时数(),00 ...

  10. elementui中表格表头设置背景色

    参考的地址: https://www.cnblogs.com/lljun/p/11551128.html 今天在设置表格的表头的时候,我通过类的时候 发现无法设置表格的表头设置不了颜色: 经过查找:原 ...