zoukankan      html  css  js  c++  java
  • spring boot1.5.6 测试类

    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!."));
    }
    }
  • 相关阅读:
    C语言文件操作
    scrapy 提取XML文档
    汇编指令和寄存器
    C语言知识点
    sqlalchemy 的sqlite多线程设置
    Unity 打AssetBundle和加载方案
    unity 4种实现动态障碍方法
    入心诗词记
    人间问答
    生活中有哪些实用的心理学知识?
  • 原文地址:https://www.cnblogs.com/faunjoe88/p/7724288.html
Copyright © 2011-2022 走看看