zoukankan      html  css  js  c++  java
  • SpringBoot单元测试示例

    ⒈控制器Action示例

     1 package cn.coreqi.controller;
     2 
     3 import org.junit.Test;
     4 import org.junit.runner.RunWith;
     5 import org.springframework.beans.factory.annotation.Autowired;
     6 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
     7 import org.springframework.boot.test.context.SpringBootTest;
     8 import org.springframework.http.MediaType;
     9 import org.springframework.test.context.junit4.SpringRunner;
    10 import org.springframework.test.web.servlet.MockMvc;
    11 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
    12 
    13 import static org.hamcrest.Matchers.equalTo;
    14 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
    15 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
    16 
    17 @RunWith(SpringRunner.class)
    18 @SpringBootTest
    19 @AutoConfigureMockMvc
    20 public class HelloControllerTest {
    21     @Autowired
    22     private MockMvc mockMvc;
    23 
    24     @Test
    25     public void contextLoads() throws Exception {
    26         mockMvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
    27                 .andExpect(status().isOk())
    28                 .andExpect(content().string(equalTo("Hello World!")));
    29     }
    30 
    31 }
  • 相关阅读:
    eclipse中的项目如何打成war包
    【SVN】Please execute the 'Cleanup' command.
    2021.06.02模拟赛DP2
    2021.05.26模拟赛 DP1
    状压DP
    高斯消元
    矩阵快速幂
    2021.05.10讲题
    Luogu P2152[SDOI 2009]Super GCD
    Tarjan
  • 原文地址:https://www.cnblogs.com/fanqisoft/p/10527152.html
Copyright © 2011-2022 走看看