Clarify Junit 5 test imports

Fix #14
This commit is contained in:
Sebastien Deleuze
2019-01-21 15:25:04 +01:00
parent 1386ad1de3
commit 21e19c2e02
5 changed files with 4 additions and 15 deletions

View File

@@ -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`
[source,kotlin]
----
@ExtendWith(SpringExtension::class)
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest
class BlogApplicationTests {

View File

@@ -1,11 +1,8 @@
package blog
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit.jupiter.SpringExtension
@ExtendWith(SpringExtension::class)
@SpringBootTest
class BlogApplicationTests {

View File

@@ -2,10 +2,8 @@ package blog
import com.nhaarman.mockito_kotlin.whenever
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
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.test.web.servlet.MockMvc
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.test.web.servlet.result.MockMvcResultMatchers.*
@ExtendWith(SpringExtension::class)
@WebMvcTest
// TODO Use constructor-based val property for @MockBean when supported, see issue spring-boot#13113
class HttpApiTests(@Autowired val mockMvc: MockMvc) {

View File

@@ -4,16 +4,12 @@ import org.assertj.core.api.Assertions.*
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.boot.test.web.client.getForEntity
import org.springframework.boot.test.web.client.getForObject
import org.springframework.http.HttpStatus
import org.springframework.test.context.junit.jupiter.SpringExtension
@ExtendWith(SpringExtension::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class IntegrationTests(@Autowired val restTemplate: TestRestTemplate) {

View File

@@ -2,13 +2,10 @@ package blog
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager
import org.springframework.test.context.junit.jupiter.SpringExtension
@ExtendWith(SpringExtension::class)
@DataJpaTest
class RepositoriesTests(@Autowired val entityManager: TestEntityManager,
@Autowired val userRepository: UserRepository,