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的更多相关文章

  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 测试时的日志级别

    1.概览 该教程中,我将向你展示:如何在测试时设置spring boot 日志级别.虽然我们可以在测试通过时忽略日志,但是如果需要诊断失败的测试,选择正确的日志级别是非常重要的. 2.日志级别的重要性 ...

  4. Spring Boot(七):spring boot测试介绍

    首先maven要引入spring-boot-starter-test这个包. 先看一段代码 @RunWith(SpringRunner.class) @SpringBootTest(webEnviro ...

  5. spring boot测试类自动注入service或dao

    使用Spring Boot进行单元测试时,发现使用@Autowired注解的类无法自动注入,当使用这个类的实例的时候,报出NullPointerException,即空指针异常. Spring Boo ...

  6. spring boot测试工具(自带)

    启动spring boot 项目(一般是openapi) http://localhost:8888/swagger-ui.html 端口号可以自己配

  7. spring boot测试

    今天在springside里试了spring boot,果然很方便,内置容器,不需要配置web.xml,简单几个文件就可以实现增删改查操作,一些配置如tomcat端口之类的直接写在applicatio ...

  8. spring boot 测试插件使用及result风格实例1&打包启动

    本节主要内容: 1:spring boot 小插件使用 2:构建第一个简单的result风格的实例并访问 3:将项目打成jar包后启动并访问. 一:添加boot devtools插件: 执行完成后,查 ...

  9. Spring Boot集成Junit测试

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

随机推荐

  1. druid数据源的加密解密工具

    数据库得加密 先来一个网上大多数的教程吧,一个比较好的教程,如下. jar包版本:druid-1.0.13.jar 1. 加密,用以下命令将用户名和密码加密 cmd命令行执行 java -cp D:/ ...

  2. Python脚本开头两行:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用

    转于:https://www.crifan.com/python_head_meaning_for_usr_bin_python_coding_utf-8/ 出处:在路上 一.基本功能 1)#!/us ...

  3. linux下dns设置详解

    DNS就是Domain Name System,它能够把形如www.21php.com这样的域名转换为211.152.50.35这样的IP地址;没有DNS,浏览21php.com这个网站时,就必须用2 ...

  4. stm32 奇怪的位赋值问题 出错了

    转载请注明出处:http://blog.csdn.net/qq_26093511/article/category/6094215 1.在51单片机里 ,下面这两种操作方法都是一样的,没有什么问题! ...

  5. jquery easyui 推荐博客 (MVC+EF+EasyUI+Bootstrap)

    构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(52)-美化EasyUI皮肤和图标   系列目录 我很久以前就想更新系统的皮肤功能,Easyui 自 ...

  6. 2.Apache + Tomcat + mod_jk实现集群服务

    转自:http://www.cnblogs.com/dennisit/p/3370220.html Tomcat中的集群原理是通过组播的方式进行节点的查找并使用TCP连接进行会话的复制. 实现效果:用 ...

  7. mongodb 分页(limit)

    db.COLLECTION_NAME.find().limit(NUMBER) db.mycol.find().limit() db.mycol.find({},{,_id:}).limit().sk ...

  8. hbase-0.98.1-cdh5.1.0伪分布式安装

    分三步: 1. 添加环境变量 2.编辑hbase-env.sh文件 3.编辑hbase-site.xml 文件 前提条件是安装好hadoop,下面展开说明 1. 添加环境变量 export HBASE ...

  9. IFrame与window对象(contentWindow)

    ref:http://blog.csdn.net/dongzhiquan/article/details/5851201 var detialIframe=document.all("det ...

  10. SCSS 中的 &::before 和 &::after

    在看一个文件的时候,发现有&::before 和 &::after, 没有理解怎么用的,因为以前在项目的css文件中,从来没有使用过,也没有见过 网上查询了一下,才发现&::b ...