BaseTestKt.kt 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package com.gxzc.zen.base
  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.junit4.SpringRunner
  7. import org.springframework.test.context.web.WebAppConfiguration
  8. import org.springframework.test.web.servlet.MockMvc
  9. import org.springframework.test.web.servlet.setup.MockMvcBuilders
  10. import org.springframework.web.context.WebApplicationContext
  11. /**
  12. * Spring单元测试基类
  13. * @author NorthLan
  14. * @date 2018/1/26
  15. * @url https://noahlan.com
  16. */
  17. @RunWith(SpringRunner::class)
  18. @SpringBootTest
  19. @WebAppConfiguration
  20. //@Transactional // 事物支持
  21. class BaseTestKt {
  22. @Autowired
  23. lateinit var webApplicationContext: WebApplicationContext
  24. lateinit var mockMvc: MockMvc
  25. @Before
  26. fun setupMockMvc() {
  27. mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build()
  28. }
  29. @Before
  30. fun initDataBase() {
  31. // Nothing
  32. }
  33. }