AbstractSpringMvcTest.java 1.0 KB

12345678910111213141516171819202122232425262728
  1. package com.xxl.job.admin.controller;
  2. import org.junit.Before;
  3. import org.junit.runner.RunWith;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.boot.test.context.SpringBootTest;
  6. import org.springframework.test.context.ContextConfiguration;
  7. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  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. @RunWith(SpringRunner.class)
  14. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  15. public class AbstractSpringMvcTest {
  16. @Autowired
  17. private WebApplicationContext applicationContext;
  18. protected MockMvc mockMvc;
  19. @Before
  20. public void setup() {
  21. this.mockMvc = MockMvcBuilders.webAppContextSetup(this.applicationContext).build();
  22. }
  23. }