先创建一个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. 百度网盘(百度云)SVIP超级会员共享账号每日更新(2023.11.25)

    来给大家伙送福利了! 一.百度网盘SVIP超级会员共享账号 可能很多人不懂这个共享账号是什么意思,小编在这里给大家做一下解答. 我们多知道百度网盘很大的用处就是类似U盘,不同的人把文件上传到百度网盘, ...

  2. [转帖]总结:shell中的if条件判断

    一.if 的基本语法 if [ command ];then xxx elif [ command ];then xxx else xxx fi 二.常见的一些写法案例 1.if [ "x$ ...

  3. [转帖]Linux系统安装之后,如何调节CPU性能策略

    https://baize.cc/posts/efc.html#:~:text=Linux%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E4%B9%8B%E5%90%8E% ...

  4. [转帖]龙叔学ES:Elasticsearch XPACK安全认证

    https://juejin.cn/post/7081994919237287950 本文已参与「新人创作礼」活动,一起开启掘金创作之路. Elasticsearch往往存有公司大量的数据,如果安全不 ...

  5. [转帖]Fiddler抓取Chrome浏览器访问baiud.com报NET::ERR_CERT_COMMON_NAME_INVALID

    错误现象 解决方法: 1.Chrome浏览器地址栏中输:chrome://net-internals/#hsts 2.在Query HSTS/PKP domain处搜索www.baidu.com网站, ...

  6. 【转帖】训练中文LLaMA大规模语言模型

    https://zhuanlan.zhihu.com/p/612752963?utm_id=0 https://github.com/CVI-SZU/Linly​github.com/CVI-SZU/ ...

  7. Python学习之十_paramiko的简单学习

    Python学习之十_paramiko的简单学习 简介 pywinrm 是python用于连接访问windows的工具 paramiko 是python用于连接访问linux的工具 ansible等工 ...

  8. [转帖]从v8到v9,Arm服务器发展之路

    https://zhuanlan.zhihu.com/p/615344155   01 ARM:3A大作 将 CPU 的设计与制造相分离的代工模式,给 AMD 提供了高度的灵活性.第二.三代 EPYC ...

  9. Redis monitor命令

    MONITOR Syntax MONITOR Available since: 1.0.0 Time complexity: ACL categories: @admin, @slow, @dange ...

  10. 数据结构与算法 第一章(48课时课程笔记)Data Structure and Algorithms

    数据结构基础知识 数据(Data):是对信息的一种符号表示.在计算机科学中是指所有能输入到计算机中并被计算机程序处理的符号的总称.数据元素(Data Element):是数据的基本单位,在计算机程序中 ...