首页>代码>spring boot简单入门demo实例>/spring-boot-helloWorld/src/test/java/com/neo/controller/HelloTests.java
package com.neo.controller;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest
public class HelloTests {

	
    private MockMvc mvc;

    @Before
    public void setUp() throws Exception {
        mvc = MockMvcBuilders.standaloneSetup(new HelloWorldController()).build();
    }

    @Test
    public void getHello() throws Exception {
        mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(content().string(equalTo("Hello World")));
    }

}
最近下载更多
whfuai  LV14 4月21日
minjing123  LV8 2022年11月12日
llqq114  LV9 2021年8月9日
皮皮虾一月  LV8 2020年12月23日
adminqujie  LV10 2020年11月22日
ewan007  LV29 2020年10月21日
sunminfy  LV6 2020年7月6日
啦啦啦7719  LV15 2020年6月24日
fictain  LV7 2020年5月25日
912299793  LV21 2020年5月6日
最近浏览更多
whfuai  LV14 4月21日
EthanGrant 2023年7月31日
暂无贡献等级
asdfg01234  LV10 2023年7月31日
高金磊abc  LV12 2023年6月22日
guviva  LV6 2023年6月12日
qazwsx0987  LV5 2023年3月29日
minjing123  LV8 2022年11月12日
Weishenghui  LV7 2022年10月23日
timezone  LV7 2022年4月26日
857248919  LV1 2022年4月21日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友