spring boot 整合測試
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
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.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class GirlTest {
@Autowired
private MockMvc mvc;
/* 不帶引數 */
@Test
public void findGirls() throws Exception{
mvc.perform(MockMvcRequestBuilders.get("/girl/girls")) //get方法訪問url
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
/* 帶引數 */
@Test
public void addGirl() throws Exception{
mvc.perform(MockMvcRequestBuilders.post("/girl/girls") //post方法訪問url
.param("name", "瀟瀟").param("age", "17")) //引數
.andExpect(MockMvcResultMatchers.status().isOk()) //校驗訪問是否成功
.andDo(MockMvcResultHandlers.print()); //列印返回引數
}
}
相關文章
- Mokito 單元測試與 Spring-Boot 整合測試Springboot
- Spring Boot單元和整合測試概述 | rieckpilSpring BootKPI
- 如何在Spring Boot中實現整合測試?Spring Boot
- Spring、Spring Boot和TestNG測試指南 – 整合測試中用Docker建立資料庫Spring BootDocker資料庫
- Spring Boot(七):spring boot測試介紹Spring Boot
- Spring Boot(十二):Spring Boot 如何測試打包部署Spring Boot
- Spring Boot 單元測試Spring Boot
- Spring Boot 中測試 CORSSpring BootCORS
- Spring、Spring Boot和TestNG測試指南 – 共享測試配置Spring Boot
- Spring+ActiveMQ整合測試SpringMQ
- spring 整合dubbo 測試搭建Spring
- 021-Spring Boot 測試Spring Boot
- Spring Boot 2.0(八):Spring Boot 整合 MemcachedSpring Boot
- Spring Boot(十八):使用 Spring Boot 整合 FastDFSSpring BootAST
- Spring Boot乾貨系列:(十二)Spring Boot使用單元測試Spring Boot
- 使用Kotlin (Spring Boot) + MockMVC + DatabaseRider輕鬆實現API整合測試KotlinSpring BootMockMVCDatabaseIDEAPI
- Spring Boot整合rabbitmqSpring BootMQ
- Spring Boot 整合 rabbitmqSpring BootMQ
- Spring Boot 整合 elasticsearchSpring BootElasticsearch
- Spring Boot 整合 dockerSpring BootDocker
- Spring Boot 整合 elkSpring Boot
- Spring Boot 整合 ApolloSpring Boot
- Spring Boot整合RedisSpring BootRedis
- Spring Boot 整合redisSpring BootRedis
- Spring Boot 整合 MyBatisSpring BootMyBatis
- Spring Boot整合SocketSpring Boot
- spring boot整合jooqSpring Boot
- Spring Boot 整合 KafkaSpring BootKafka
- spring boot 整合mybatisSpring BootMyBatis
- Spring Boot整合Spring BatchSpring BootBAT
- Spring Boot整合Spring SecuritySpring Boot
- Spring Boot整合Spring AopSpring Boot
- Spring boot學習(三) Spring boot整合mybatisSpring BootMyBatis
- 八、Spring Boot整合Spring Security之前後分離認證最佳實現對接測試Spring Boot
- Spring Boot:整合Spring Data JPASpring Boot
- spring-boot+spring-session整合SpringbootSession
- 使用 Spring Boot 進行單元測試Spring Boot
- Spring Boot 構建 Restful API 和測試Spring BootRESTAPI