Skip to content

Commit

Permalink
Upgrade to JUnit 5 !!!
Browse files Browse the repository at this point in the history
This commit also enables per class test lifecycle which allows
faster test execution and non static @BeforeAll / @afterall
member functions.
  • Loading branch information
sdeleuze committed Sep 12, 2017
1 parent ac1a0d6 commit 05c68f4
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 22 deletions.
16 changes: 11 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repositories {
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xjsr305-annotations=enable")
freeCompilerArgs = listOf("-Xjsr305-annotations=enable")
}
}

Expand All @@ -57,18 +57,24 @@ dependencies {
}
compileOnly("org.springframework:spring-context-indexer")
compile("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
testCompile("org.springframework.boot:spring-boot-starter-test")

runtime("de.flapdoodle.embed:de.flapdoodle.embed.mongo")
compile("com.samskivert:jmustache:1.13")
compile("com.atlassian.commonmark:commonmark:0.9.0")
compile("com.atlassian.commonmark:commonmark-ext-autolink:0.9.0")

compile("com.google.code.findbugs:jsr305:3.0.2") // Needed for now, could be removed when KT-19419 will be fixed

testCompile("io.projectreactor:reactor-test")
compile("com.google.code.findbugs:jsr305:3.0.2") // Needed for now, could be removed when KT-19419 will be fixed

compile("com.fasterxml.jackson.module:jackson-module-kotlin")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")

testCompile("org.springframework.boot:spring-boot-starter-test") {
exclude(module = "junit")
}
testCompile("org.junit.jupiter:junit-jupiter-api")
testRuntime("org.junit.jupiter:junit-jupiter-engine")
testRuntime("org.junit.platform:junit-platform-launcher")
testCompile("io.projectreactor:reactor-test")
}

task<GulpTask>("gulpBuild") {
Expand Down
10 changes: 5 additions & 5 deletions src/test/kotlin/mixit/integration/AbstractIntegrationTests.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package mixit.integration

import org.junit.Before
import org.junit.runner.RunWith
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.web.reactive.function.client.WebClient

@RunWith(SpringRunner::class)
@ExtendWith(SpringExtension::class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
abstract class AbstractIntegrationTests {

Expand All @@ -17,7 +17,7 @@ abstract class AbstractIntegrationTests {

lateinit var client: WebClient

@Before
@BeforeAll
fun setup() {
client = WebClient.create("http://localhost:$port")
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/kotlin/mixit/integration/EventIntegrationTests.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package mixit.integration

import mixit.model.Event
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.springframework.http.MediaType.APPLICATION_JSON
import org.springframework.web.reactive.function.client.bodyToMono
import org.springframework.web.reactive.function.client.bodyToFlux
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/mixit/integration/TalkIntegrationTests.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package mixit.integration

import mixit.model.Talk
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.springframework.http.MediaType.APPLICATION_JSON
import org.springframework.web.reactive.function.client.bodyToFlux
import reactor.test.test
Expand Down
5 changes: 2 additions & 3 deletions src/test/kotlin/mixit/integration/UserIntegrationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package mixit.integration

import mixit.model.Role
import mixit.model.User
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.springframework.http.MediaType.APPLICATION_JSON
import org.springframework.web.reactive.function.client.bodyToFlux
import org.springframework.web.reactive.function.client.bodyToMono
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mixit.integration

import org.junit.Test
import org.junit.jupiter.api.Test
import org.springframework.http.HttpStatus.*
import org.springframework.http.MediaType.*
import reactor.test.test
Expand Down
5 changes: 2 additions & 3 deletions src/test/kotlin/mixit/util/ExtensionsTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package mixit.util

import org.junit.Test

import org.junit.Assert.*
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

/**
* Unit tests for Extensions
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
junit.jupiter.testinstance.lifecycle.default = per_class

2 comments on commit 05c68f4

@sbrannen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you not run the test suite in Gradle?

@sdeleuze
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbrannen Good catch, I fixed that via bb74187

Please sign in to comment.