BaseJunitTest.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package com.uas.platform.b2c;
  2. import org.junit.Before;
  3. import org.junit.runner.RunWith;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.test.context.ContextConfiguration;
  6. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  7. import org.springframework.test.context.transaction.TransactionConfiguration;
  8. import org.springframework.test.context.web.WebAppConfiguration;
  9. import org.springframework.test.web.servlet.MockMvc;
  10. import org.springframework.test.web.servlet.setup.MockMvcBuilders;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import org.springframework.web.context.WebApplicationContext;
  13. /**
  14. * Spring MVC 测试基类,所有测试类继承自这个类就可以直接写单元测试
  15. * @author stg
  16. * @date 2017年11月8日16:48:18
  17. */
  18. @RunWith(SpringJUnit4ClassRunner.class)
  19. @ContextConfiguration("classpath:spring/context.xml")
  20. @WebAppConfiguration("")
  21. @Transactional
  22. @TransactionConfiguration(defaultRollback = true)
  23. public class BaseJunitTest {
  24. @Autowired
  25. protected WebApplicationContext wac;
  26. protected MockMvc mockMvc;
  27. /**
  28. * 前置防范,配置MVCMock
  29. */
  30. @Before
  31. public void setup() {
  32. this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
  33. }
  34. }