@@ -270,12 +270,14 @@ dependencies {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
Refresh Gradle configuration, and open `BlogApplicationTests` to replace `@RunWith(SpringRunner::class)` by `@ExtendWith(SpringExtension::class)`.
|
Refresh Gradle configuration, open `BlogApplicationTests` and update imports as bellow and remove `@RunWith(SpringRunner::class)` since `@SpringBootTest` is already annotated with JUnit 5 `@ExtendWith(SpringExtension::class)` as of Spring Boot 2.1.
|
||||||
|
|
||||||
`src/test/kotlin/blog/BlogApplicationTests.kt`
|
`src/test/kotlin/blog/BlogApplicationTests.kt`
|
||||||
[source,kotlin]
|
[source,kotlin]
|
||||||
----
|
----
|
||||||
@ExtendWith(SpringExtension::class)
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class BlogApplicationTests {
|
class BlogApplicationTests {
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
package blog
|
package blog
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
|
||||||
|
|
||||||
@ExtendWith(SpringExtension::class)
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class BlogApplicationTests {
|
class BlogApplicationTests {
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ package blog
|
|||||||
|
|
||||||
import com.nhaarman.mockito_kotlin.whenever
|
import com.nhaarman.mockito_kotlin.whenever
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
import org.springframework.boot.test.mock.mockito.MockBean
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
|
||||||
@@ -13,7 +11,6 @@ import org.mockito.Mockito.any
|
|||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
|
||||||
|
|
||||||
@ExtendWith(SpringExtension::class)
|
|
||||||
@WebMvcTest
|
@WebMvcTest
|
||||||
// TODO Use constructor-based val property for @MockBean when supported, see issue spring-boot#13113
|
// TODO Use constructor-based val property for @MockBean when supported, see issue spring-boot#13113
|
||||||
class HttpApiTests(@Autowired val mockMvc: MockMvc) {
|
class HttpApiTests(@Autowired val mockMvc: MockMvc) {
|
||||||
|
|||||||
@@ -4,16 +4,12 @@ import org.assertj.core.api.Assertions.*
|
|||||||
import org.junit.jupiter.api.AfterAll
|
import org.junit.jupiter.api.AfterAll
|
||||||
import org.junit.jupiter.api.BeforeAll
|
import org.junit.jupiter.api.BeforeAll
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
import org.springframework.boot.test.web.client.TestRestTemplate
|
import org.springframework.boot.test.web.client.TestRestTemplate
|
||||||
import org.springframework.boot.test.web.client.getForEntity
|
import org.springframework.boot.test.web.client.getForEntity
|
||||||
import org.springframework.boot.test.web.client.getForObject
|
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
|
||||||
|
|
||||||
@ExtendWith(SpringExtension::class)
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
class IntegrationTests(@Autowired val restTemplate: TestRestTemplate) {
|
class IntegrationTests(@Autowired val restTemplate: TestRestTemplate) {
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ package blog
|
|||||||
|
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager
|
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
|
||||||
|
|
||||||
@ExtendWith(SpringExtension::class)
|
|
||||||
@DataJpaTest
|
@DataJpaTest
|
||||||
class RepositoriesTests(@Autowired val entityManager: TestEntityManager,
|
class RepositoriesTests(@Autowired val entityManager: TestEntityManager,
|
||||||
@Autowired val userRepository: UserRepository,
|
@Autowired val userRepository: UserRepository,
|
||||||
|
|||||||
Reference in New Issue
Block a user