首页 > 编程语言 > 详细

springboot测试

时间:2018-03-08 22:26:54      阅读:220      评论:0      收藏:0      [点我收藏+]
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测试

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!