MockMvc 对 Spring Boot 进行单元测试
2024-09-12 06:45:10
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.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void testHello() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/hi").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string("Hello world"));
}
}
最新文章
- EZchip将推全球首款100核64位ARM A-53芯片
- UIViewContentMode各类型效果
- SQL中CONVERT日期不同格式的转换用法
- 实现鼠标拖动canvas绘制的图片
- LINUX内核分析期末总结
- libcurl with telnet
- [转]Efficiently Paging Through Large Amounts of Data
- 关于android WebViewClient的方法解释
- 怎么让LinearLayout充满ScrollView
- iOS上用FTGL显示定制Truetype字体碰到的问题
- js冒泡事件的特例toggle无法实现阻止冒泡——slideDown()和slideUp()
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-006-Pizza例子的支付流程
- chrome扩展——Postman
- CentOS安装JDK7
- 用xerces-c来进行xml schema校验
- Ant Design Pro+Electron+electron-builder实现React应用脱离浏览器,桌面安装运行
- centos7 关闭selinux
- javascript Object的新方法
- springMVC 几种页面跳转方式
- Centos7 配置ssh 免秘钥登陆