package com.qutaoyao.demo.web;

import com.qutaoyao.demo.web.controller.HelloController;
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.RequestBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @RunWith(SpringRunner.class)
@SpringBootTest
public class HelloControllerTests { private MockMvc mvc; @Before
public void init(){
this.mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
} @Test
public void sayHi() throws Exception{
RequestBuilder req = get("/hello/hi"); mvc.perform(req).andExpect(status().isOk()).andExpect(content().string("Hello World!."));
}
}

spring boot1.5.6 测试类的更多相关文章

  1. spring boot1.5.6 测试类1

    package com.example.demo; import org.junit.Before;import org.junit.Test; import org.junit.runner.Run ...

  2. Mybatis+Spring整合后Mapper测试类编写

    public class UserMapperTest { private ApplicationContext applicationContext; @Before public void ini ...

  3. spring boot 单元测试 --- 在测试类使用 javabean注解操作接口

    1.依赖包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>s ...

  4. spring 测试类test测试方法

    实例掩码地址为:孔浩组织结构设计 web.xml配置文件: <!-- Spring 的监听器可以通过这个上下文参数来获取beans.xml的位置 --> <context-param ...

  5. 测试类异常Manual close is not allowed over a Spring managed SqlSession

    在用Spring 和mybatis整合的 写测试类的时候报出解决办法:在全局配置文件   class="org.mybatis.spring.SqlSessionTemplate" ...

  6. Injection of autowired dependencies failed; autowire 自动注入失败,测试类已初始化过了Spring容器。

    1 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creat ...

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

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

  8. spring hibernate 事务整合 使用测试类 事务不自动提交的问题!!!

    使用JUnit 测试hibernate 事务管理的时候应注意 ,测试类完成是默认回滚的. 所以只能查询数据库却不能增删改数据库. 应该在测试类上面加上注解 @Rollback(false)  表似默认 ...

  9. 二 Spring的IOC入门,环境搭建,Spring测试类

    IOC:inversion of Control  控制反转,Spring框架的核心.削减计算机程序的耦合问题,把对象(例如JDBC)的创建权交给Spring. IOC的两种类型: 依赖注入: 依赖查 ...

随机推荐

  1. RequireJS -Javascript模块化(二、模块依赖)

    上一篇文章中简单介绍了RequireJs的写法和使用,这节试着写下依赖关系 需求描述:我们经常写自己的js,在元素选择器这方面,我们可能会用jquery的$("#id")id选择器 ...

  2. 转 ogg issue

    1.http://www.dbdream.com.cn/2013/05/17/ogg-00446%E9%94%99%E8%AF%AF%E8%A7%A3%E5%86%B3/ OGG-00446错误解决 ...

  3. MySQL · 引擎特性 · InnoDB index lock前世今生

    http://mysql.taobao.org/monthly/2015/07/05/ MySQL · 引擎特性 · InnoDB index lock前世今生 前言 InnoDB并发过程中使用两类锁 ...

  4. shell中获取本机ip地址

    shell中获取本机ip地址 方法一: /sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr ...

  5. 性能测试工具LoadRunner12-LR之Virtual User Generator 脚本编写验证步骤以及LR常见错误处理方法

    验证脚本比较好的流程: Generate:录制或开发脚本 SUSI(Single User Single Iteration,单用户单循环):运行录制生成的脚本,解决可能存在的关键问题 SUMI(Si ...

  6. 使用WindowsAPI播放PCM音频

    这一篇文章同上一篇<使用WindowsAPI获取录音音频>原理具有相似之处,不再详细介绍函数与结构体的参数 1. waveOutGetNumDevs 2. waveOutGetDevCap ...

  7. 监听outlook新邮件

    using System; using System.Linq; using Microsoft.Office.Interop.Outlook; using System.Collections.Ge ...

  8. nexus 私服相关的配置

    1 上传到nexus的配置 1 settings.xml <server> <id>releases</id> <username>admin</ ...

  9. 位于XDB的服务器localhost要求用户名和密码,端口占用

    问题现象: 从MyEclipse启动部署在tomcat上的web程序后,出现如下问题: 然后访问tomcat主页(http://localhost:8080/),弹出如下对话框: 问题原因: 机器上安 ...

  10. Git提交代码到主分区

    git 提交代码,本地新建一个my分支,不从本地master分支直接上传,而是先从本地my分支上提交至本地master分支,然后本地master提交至远程master分支 上.前提是远程只有一个mas ...