Spring Boot 测试 junit
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.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner; import com.lat.theonex.SportNativeServiceApp; @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = {SportNativeServiceApp.class })
public class SpringBootTest_Example { @Autowired
private TestRestTemplate restTemplate; @Test
public void testXXX(){
// TODO
} }
加入Maven依赖
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
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 测试时的日志级别
1.概览 该教程中,我将向你展示:如何在测试时设置spring boot 日志级别.虽然我们可以在测试通过时忽略日志,但是如果需要诊断失败的测试,选择正确的日志级别是非常重要的. 2.日志级别的重要性 ...
- Spring Boot(七):spring boot测试介绍
首先maven要引入spring-boot-starter-test这个包. 先看一段代码 @RunWith(SpringRunner.class) @SpringBootTest(webEnviro ...
- spring boot测试类自动注入service或dao
使用Spring Boot进行单元测试时,发现使用@Autowired注解的类无法自动注入,当使用这个类的实例的时候,报出NullPointerException,即空指针异常. Spring Boo ...
- spring boot测试工具(自带)
启动spring boot 项目(一般是openapi) http://localhost:8888/swagger-ui.html 端口号可以自己配
- spring boot测试
今天在springside里试了spring boot,果然很方便,内置容器,不需要配置web.xml,简单几个文件就可以实现增删改查操作,一些配置如tomcat端口之类的直接写在applicatio ...
- spring boot 测试插件使用及result风格实例1&打包启动
本节主要内容: 1:spring boot 小插件使用 2:构建第一个简单的result风格的实例并访问 3:将项目打成jar包后启动并访问. 一:添加boot devtools插件: 执行完成后,查 ...
- Spring Boot集成Junit测试
添加依赖: 在测试类上添加注解:
随机推荐
- bzoj 3730 震波 —— 动态点分治+树状数组
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3730 建点分树,每个点记两个树状数组,存它作为重心管辖的范围内,所有点到它的距离情况和到它在 ...
- 对API的理解
一. API(Application Programming Interface,应用程序编程接口) 1)定义:API是远程服务器或者操作系统的一些函数,是它们的一部分: 2)功能:用来接收应用程序( ...
- JSP介绍(4)--- JSP Cookie 处理
Cookie是存储在客户机的文本文件,它们保存了大量轨迹信息. JSP脚本通过request对象中的getCookies()方法来访问这些cookie,这个方法会返回一个Cookie对象的数组. 通常 ...
- CentOS 配置RDP
XRDP服务器 CentOS安装XRDP实现远程桌面访问: 由于安装的是远程桌面,因此需要安装桌面显示服务:# yum install vnc-server 下面开始配置XRDP服务 l 配置环境: ...
- 洛谷-关押罪犯-NOIP2010提高组复赛
题目描述 S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用“怨气值”(一个正整数值)来表示 ...
- 关于Android进程的启动和消亡
在打开一个应用程序的时候,packagemanager会根据manifest文件去查找有没有相应的进程已启动,若果没有启动,那么就启动一个新的进程 进程退出有两种方式,用finish结束主activi ...
- 主线程与UI线程简介
---------------siwuxie095 Java 程序的主线程 当 Java 程序启动时,一个线程立刻运行,该线程通常叫做程 ...
- Ubuntu12.04安装 vsftpd
Ubuntu12.04 FTP 的配置 ubuntu安装ftp服务器 1: 安装vsftpd ~$ sudo apt-get install vsftpd 2: 配置vsftpd 2.1 修改vs ...
- The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object
The project was not built since its build path is incomplete. Cannot find the class file for java.la ...
- Java数学相关工具类
1.求百分比 public class Test1 { public static String myPercent(int y, int z) { String baifenbi = "& ...