Skip to content

Commit 7f2691a

Browse files
committed
add web test
1 parent fcbe726 commit 7f2691a

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

spring-boot-mybatis-xml/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>1.4.1.RELEASE</version>
17+
<version>1.5.9.RELEASE</version>
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.neo.web;
2+
3+
4+
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.http.MediaType;
11+
import org.springframework.test.context.junit4.SpringRunner;
12+
import org.springframework.test.web.servlet.MockMvc;
13+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
14+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
15+
import org.springframework.web.context.WebApplicationContext;
16+
17+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
18+
19+
@RunWith(SpringRunner.class)
20+
@SpringBootTest
21+
public class UserControllerTest {
22+
@Autowired
23+
private WebApplicationContext wac;
24+
private MockMvc mockMvc;
25+
26+
@Before
27+
public void setUp() throws Exception {
28+
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); //初始化MockMvc对象
29+
}
30+
31+
@Test
32+
public void getUsers() throws Exception {
33+
mockMvc.perform(MockMvcRequestBuilders.post("/getUsers")
34+
.accept(MediaType.APPLICATION_JSON_UTF8)).andDo(print());
35+
}
36+
37+
}

0 commit comments

Comments
 (0)