测试时,@SpringApplicationConfiguration(classes = Application.class) 报错,注解不能导入。

在学习spring boot时,按照文档学习时测试时,我也是遇到这个问题,看了好多资料,有的说是这个注解在1.4就被替换了,我用的1.5.2版本的,直接用自动生成的两个注解就可以实现测试功能。
@RunWith(SpringRunner.class)
@SpringBootTest 测试代码:

package com.didispace.hello;

import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

@RunWith(SpringRunner.class)
@SpringBootTest
public class HelloAppTests {

//模拟调用controller接口发起请求
private MockMvc mvc;

@Before
public void setUp(){
mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
}

@Test
public void hello() throws Exception{
mvc.perform(MockMvcRequestBuilders.get("/hello")
.accept(org.springframework.http.MediaType.APPLICATION_JSON)
).andExpect(content().string(equalTo("hello")))
.andExpect(status().isOk());
}
}

springboot测试时 SpringApplicationConfiguration注解不能用的更多相关文章

  1. JPA实体类注解、springboot测试类、lombok的使用

    前提准备: 搭建一个springboot项目,详情请参见其它博客:点击前往 1 引入相关依赖 web.mysql.jpa.lombok <?xml version="1.0" ...

  2. SpringBoot系列三:SpringBoot基本概念(统一父 pom 管理、SpringBoot 代码测试、启动注解分析、配置访问路径、使用内置对象、项目打包发布)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.了解SpringBoot的基本概念 2.具体内容 在之前所建立的 SpringBoot 项目只是根据官方文档实现的一个基础程 ...

  3. SpringBoot学习笔记<二>注解

    此篇为项目作结之笔记,关于注解. 项目启动入口@SpringBootApplication[必选]  @ServletComponentScan[可选] 注解后: Servlet.Filter.Lis ...

  4. Spring Boot 测试时的日志级别

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

  5. springboot测试、打包、部署

    本文使用<springboot集成mybatis(一)>项目,依次介绍springboot测试.打包.部署. 大多数朋友是做后端的,也就是为其他系统或者前端UI提供Rest API服务. ...

  6. SpringBoot Mybatis整合(注解版),SpringBoot集成Mybatis(注解版)

    SpringBoot Mybatis整合(注解版),SpringBoot集成Mybatis(注解版) ================================ ©Copyright 蕃薯耀 2 ...

  7. SpringBootTest单元测试实战、SpringBoot测试进阶高级篇之MockMvc讲解

    1.@SpringBootTest单元测试实战 简介:讲解SpringBoot的单元测试 1.引入相关依赖 <!--springboot程序测试依赖,如果是自动创建项目默认添加--> &l ...

  8. Redis3.2.5 集群搭建以及Spring-boot测试

    1:集群中的机器信息 IP PORT 192.168.3.10 7000,7001,7002 192.168.3.11 7004,7005,7006 2:安装Redis 分别在10与11机器上面安装R ...

  9. springboot中的常用注解

    springboot中的常用注解个人觉得springboor中常用的注解主要可以分为三种:放入容器型注解.从容器中取出型注解和功能型注解.其中的放入容器型和从容器中取出型就是我们平时所说的控制反转和依 ...

随机推荐

  1. task optimization

    Requirements: Tasks have Dependencies Running the task in Multi thread Links http://en.wikipedia.org ...

  2. 【转】实战USB接口手机充电 看3.0/2.0谁更快

    原文网址:http://mb.it168.com/a2012/0816/1385/000001385641_all.shtml [IT168 应用]当下,越来越多的电脑都已普及USB 3.0接口,新买 ...

  3. python 函数参数的传递(参数带星号的说明) 元组传递 字典传递

    python中函数参数的传递是通过赋值来传递的.函数参数的使用又有俩个方面值得注意:1.函数参数是如何定义的 2.在调用函数的过程中参数是如何被解析 先看第一个问题,在python中函数参数的定义主要 ...

  4. Joyoi花店橱窗(原tyvj1124)

    题目:http://www.joyoi.cn/problem/tyvj-1124 两点注意!!! 1.滚动数组的初始化: 2.字典序操作! 感到很有趣!!! #include<iostream& ...

  5. SQL Server Reporting Service 报错:报表服务器无法解密用于访问报表服务器数据库中的敏感数据或加密数据的对称密钥,必须还原备份密钥或删除所有加密的内容。

    出现这个问题,可以通过reporting services 配置管理工具来处理 首先,打开配置管理工具,连接. 在左侧的导航选项中选择Encryption Keys,将出现如图所示的界面,在右侧点击d ...

  6. Debug---Eclipse断点调试基础

    1.进入debug模式(基础知识列表)1.设置断点 2.启动servers端的debug模式 3.运行程序,在后台遇到断点时,进入debug调试状态 ========================= ...

  7. js 取整

    1.丢弃小数部分,保留整数部分 js:parseInt(7/2)  2.向上取整,有小数就整数部分加1  js: Math.ceil(7/2)  3,四舍五入.  js: Math.round(7/2 ...

  8. Bluez相关的各种tools的使用

    7.1        Bccmd Bccmd是用来和CSR的芯片进行BCCMD(Bluecore command protocol)通讯的一个工具.BCCMD并非蓝牙协议栈的标准,而是CSR芯片的专属 ...

  9. [模板] KMP字符串匹配标准代码

    之前借鉴了某个模板的代码.我个人认为这份代码写得很好.值得一背. #include<bits/stdc++.h> using namespace std; const int N=1000 ...

  10. QSqlDatabase: QMYSQL driver not loaded

    转载:KiteRunner24 在Qt 5.9中使用数据库连接时,弹出下面的错误: QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: avail ...