3 Star 6 Fork 5

jarchan / spring-test-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
BootMvc_1_Test.java 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
jarchan 提交于 2017-08-23 15:50 . add mvc examples
package me.chanjar.springboot1;
import me.chanjar.web.FooController;
import me.chanjar.web.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.web.servlet.MockMvc;
import org.testng.annotations.Test;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@WebMvcTest
@ContextConfiguration(classes = { FooController.class, FooImpl.class })
public class BootMvc_1_Test extends AbstractTestNGSpringContextTests {
@Autowired
private MockMvc mvc;
@Test
public void testController() throws Exception {
this.mvc.perform(get("/foo/check-code-dup").param("code", "123"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().string("true"));
}
}
Java
1
https://gitee.com/chanjarster/spring-test-examples.git
git@gitee.com:chanjarster/spring-test-examples.git
chanjarster
spring-test-examples
spring-test-examples
master

搜索帮助