File tree 2 files changed +38
-1
lines changed
src/test/java/com/neo/web 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 14
14
<parent >
15
15
<groupId >org.springframework.boot</groupId >
16
16
<artifactId >spring-boot-starter-parent</artifactId >
17
- <version >1.4.1 .RELEASE</version >
17
+ <version >1.5.9 .RELEASE</version >
18
18
<relativePath /> <!-- lookup parent from repository -->
19
19
</parent >
20
20
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments