码迷,mamicode.com
首页 > 编程语言 > 详细

springboot测试

时间:2018-03-08 23:01:14      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:figure   temp   template   ott   you   list   except   string   user   

package club.iyousi.controller;

import javafx.application.Application;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
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.MockMvcResultMatchers;

import java.util.HashMap;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class HelloTest {
    @Autowired
    private MockMvc mvc;

    @Test
    public void listUser() throws Exception {
        mvc.perform(MockMvcRequestBuilders.get("/users"))
                .andExpect(MockMvcResultMatchers.status().isOk())//通过
                .andExpect(MockMvcResultMatchers.content().string("[]"));//期望结果是一个值
    }

    @Test
    public void post() throws Exception {
        mvc.perform(MockMvcRequestBuilders.post("/users").param("id","1").param("name","sfz").param("age","12"))
                .andExpect(MockMvcResultMatchers.status().isOk())//通过
                .andExpect(MockMvcResultMatchers.content().string("success"));//期望结果是一个值
    }
}

 

springboot测试

标签:figure   temp   template   ott   you   list   except   string   user   

原文地址:https://www.cnblogs.com/songfahzun/p/8531106.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!