forked from rbmonster/learning-note
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebLayerTest.java
More file actions
55 lines (52 loc) · 2.17 KB
/
Copy pathWebLayerTest.java
File metadata and controls
55 lines (52 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import com.four.unittest.controller.UnitController;
import com.four.unittest.UnitTestApplication;
import org.junit.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import static org.hamcrest.Matchers.containsString;
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;
/**
* <pre>
* @Description:
*
* </pre>
*
* @version v1.0
* @ClassName: WebLayerTest
* @Author: sanwu
* @Date: 2021/3/18 0:38
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = UnitTestApplication.class)
@WebMvcTest(UnitController.class)
public class WebLayerTest implements ApplicationContextAware {
@Autowired
private MockMvc mockMvc;
@Test
public void shouldReturnDefaultMessage() throws Exception {
this.mockMvc.perform(get("/unit/one"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().string(containsString("one")));
}
ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}