zoukankan      html  css  js  c++  java
  • Spring Boot 单元测试

    Spring Boot 单元测试

    package com.stono.sc_page017;
    
    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.test.context.junit4.SpringJUnit4ClassRunner;
    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(SpringJUnit4ClassRunner.class)
    @SpringBootTest(classes = ScPage017Application.class)
    @WebAppConfiguration
    public class HelloApplicationTests {
        private MockMvc mvc;
    
        @Before
        public void setUp() throws Exception {
            mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
        }
    
        @Test
        public void hello() throws Exception {
            mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
                    .andExpect(status().isOk())
                    .andExpect(content().string(equalTo("hello, world")));
        }
    }
  • 相关阅读:
    PHP获取某年第几周的开始日期和结束日期
    Java多线程(一)
    Java多线程学习
    使用反射实现 webdriver page 类
    PageObjects 设计模式
    Selenium WebDriver 工作原理
    Selenium2.0 Webdriver 随笔
    Selenium-Grid2 配置RemoteWebDriver
    Java多线程基础(二)
    Java多线程基础(一)
  • 原文地址:https://www.cnblogs.com/stono/p/8622934.html
Copyright © 2011-2022 走看看