yantian yue
2023-10-23 0d7d6a88080dc8759ef84ed5ad7875f25642df6c
提交 | 用户 | 时间
1ac2bc 1 package cn.stylefeng.guns.base;
2
3 import cn.stylefeng.guns.GunsApplication;
4 import org.junit.Before;
5 import org.junit.runner.RunWith;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.boot.test.context.SpringBootTest;
8 import org.springframework.test.context.junit4.SpringRunner;
9 import org.springframework.test.context.web.WebAppConfiguration;
10 import org.springframework.test.web.servlet.MockMvc;
11 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
12 import org.springframework.web.context.WebApplicationContext;
13
14
15 /**
16  * 基础测试类
17  *
18  * @author stylefeng
19  * @Date 2017/5/21 16:10
20  */
21 @RunWith(SpringRunner.class)
22 @SpringBootTest(classes = GunsApplication.class)
23 @WebAppConfiguration
24 //@Transactional //打开的话测试之后数据可自动回滚
25 public class BaseJunit {
26
27     @Autowired
28     WebApplicationContext webApplicationContext;
29
30     protected MockMvc mockMvc;
31
32     @Before
33     public void setupMockMvc() {
34         mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
35     }
36
37     @Before
38     public void initDatabase() {
39     }
40 }