• springboot测试


    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"));//期望结果是一个值
        }
    }
  • 相关阅读:
    HDU 4814 Golden Radio Base
    我对Swift的几点疑问
    【UTR #1】ydc的大树
    jsp中的隐含9对象
    动作元素
    指令元素
    JSP语法
    设计模式六大原则(6):开闭原则
    设计模式六大原则(5):迪米特法则
    设计模式六大原则(4):接口隔离原则
  • 原文地址:https://www.cnblogs.com/songfahzun/p/8531106.html
Copyright © 2020-2023  润新知