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. windows环境搭建禅道项目管理工具

    zentao官网的几个网址 http://www.zentao.net/ http://www.zentao.net/article-view-79863.html   搭建环境需要下载两个文件 1) ...

  2. c++中 重载 覆盖 隐藏的区别 附加 mutable笔记

    成员函数被重载的特征有: 1) 相同的范围(在同一个类中): //2) 函数名字相同: 3) 参数不同: 4) virtual关键字可有可无. 覆盖的特征有: 1) 不同的范围(分别位于派生类与基类) ...

  3. mobiscroll 日期问题

    做的一个项目中用到了mobiscroll日期控件,设置距离当前日期往前推一个月的时间出现如下图问题 弹出窗默认的年份不对,后来查找原因是初始化属性配置有问题,应该将设置为dateFormat:'yy- ...

  4. Unity3d 破解

    在官网上或者其他地方下载unity3d后 运行注册机,需要详细的设置可以点击edit   一.点击browse,选择安装unity目录下的Editor文件夹 二.选择path,会提示Pathed 三. ...

  5. python 编程,应该养成哪些好的习惯

    python 编程,应该养成哪些好的习惯? https://www.zhihu.com/question/28966220 无缓冲输出 python -u  sys.stdout.flush() 性能 ...

  6. (转)Awk使用案例总结(运维必会)

    以下知识点可能有不对之处,请参考最新Awk学习文章:http://lizhenliang.blog.51cto.com/7876557/1892112 原文:http://blog.51cto.com ...

  7. contiki源码阅读之list

    我们阅读一下contiki的源码,list.c(路径是./core/lib/list.h). #include "lib/list.h" #define NULL 0 struct ...

  8. fillder script使用

    打开fiddler script editor 在fiddler中Rules -> Customize Rules打开 在editor中点击open, 打开CustomRules.js文件, 对 ...

  9. Navicat连接Oracle数据库报错ORA-28547解决方法

    先说明下我机器的环境: 1.Win10 - 64bit 2.Navicat Premium_11.2.7  - 64bit 3.未安装Oracle数据库(包括Client也未安装) 解决方法: 1.下 ...

  10. fiddler filters 使用(fiddler只显示指定请求,fiddler不显示指定请求,即filter请求过滤)(转)

    fiddler filters 使用(fiddler只显示指定请求,fiddler不显示指定请求,即filter请求过滤) Fiddler 有一个filters可以很好的帮助我们只显示我们关系的请求或 ...