package com.example.demo;

import org.junit.Before;
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; 
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.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; 
import com.example.demo.controller.HelloWorldController;

@RunWith(SpringRunner.class)
@SpringBootTest
public class HelloWorldControlerTests {
     private MockMvc mvc;
        @Before
        public void setUp() throws Exception {
            mvc = MockMvcBuilders.standaloneSetup(new HelloWorldController()).build();
        }
        @Test
        public void getHello() throws Exception {
        mvc.perform(MockMvcRequestBuilders.get("/sayHello").accept(MediaType.APPLICATION_JSON))
                    .andExpect(MockMvcResultMatchers.status().isOk())
                    .andDo(MockMvcResultHandlers.print())
                    .andReturn();
        }
        
        
}

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

  1. spring boot1.5.6 测试类

    package com.qutaoyao.demo.web; import com.qutaoyao.demo.web.controller.HelloController;import org.ju ...

  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. 主席树-----动态开点,不hash

    POJ - 2104 第k大 #include <cstdio> #include <cstdlib> #include <cstring> #include &l ...

  2. (转)shell中各种括号的作用()、(())、[]、[[]]、{}

    shell中各种括号的作用().(()).[].[[]].{} 原文:http://www.jb51.net/article/60326.htm http://blog.csdn.net/good_h ...

  3. Kudu 常见的几个应用场景

    不多说,直接上干货! Kudu 常见的几个应用场景 实时更新的应用.刚刚到达的数据就马上要被终端用户使用访问到. 时间序列相关的应用,需要同时支持: 根据海量历史数据查询. 必须非常快地返回关于单个实 ...

  4. 【LDAP】LDAP介绍

    原文:http://ldapman.org/articles/intro_to_ldap.html原文作者:Michael Donnelly 什么是LDAP? LDAP的英文全称是Lightweigh ...

  5. CentOS 使用RPM方式安装MySQL5.6

    转载自:http://blog.csdn.net/liumm0000/article/details/18841197 RPM方式安装MySQL5.6 a. 检查MySQL及相关RPM包,是否安装,如 ...

  6. csdn下载

    按次收费: http://www.itziy.com/

  7. carousel 插件隐藏列表中几项导致左右切换出错

    1. 一般的应用场景: 用于左右快速切换显示的列表内容,比如对员工的切换. 对于这种情况必不可少需要按照部门进行搜索,目前我的做法是首次加载所有该用户可以查看的员工列表,选择部门后又选择的隐藏掉其他不 ...

  8. The eleventh day

    What's the damage? Thanks so much for fixing the break on my car . What's the damage for the work yo ...

  9. Unified Service Desk Overview

    As we implement CRM in enterprise, we usually integrate with many other information system such as E ...

  10. Differences or similarities between Java and C++

    “作为一名C++程序员,我们早已掌握了面向对象Object-oriented Programming程序设计的基本概念,而且Java的语法无疑是非常熟悉的.事实上,Java本来就是从C++衍生出来的. ...