Skip to content

Commit 12c1ad2

Browse files
garyrussellartembilan
authored andcommitted
Support JUnit5 in tests
1 parent adb3487 commit 12c1ad2

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

Diff for: build.gradle

+19-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ subprojects { subproject ->
7474
hamcrestVersion = '1.3'
7575
jacksonVersion = '2.9.4'
7676
jaywayJsonPathVersion = '2.4.0'
77-
junitVersion = '4.12'
77+
junit4Version = '4.12'
78+
junitJupiterVersion = '5.1.0'
79+
junitPlatformVersion = '1.1.0'
80+
junitVintageVersion = '5.1.0'
7881
kafkaVersion = '1.0.0'
7982
mockitoVersion = '2.15.0'
8083
scalaVersion = '2.11'
@@ -93,6 +96,19 @@ subprojects { subproject ->
9396
toolVersion = '0.7.9'
9497
}
9598

99+
// dependencies that are common across all java projects
100+
dependencies {
101+
testCompile "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
102+
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion"
103+
testRuntime "org.junit.platform:junit-platform-launcher:$junitPlatformVersion"
104+
105+
// To support JUnit 4 tests
106+
testRuntime "org.junit.vintage:junit-vintage-engine:$junitVintageVersion"
107+
108+
// To avoid compiler warnings about @API annotations in JUnit code
109+
testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'
110+
}
111+
96112
// enable all compiler warnings; individual projects may customize further
97113
[compileJava, compileTestJava]*.options*.compilerArgs = ['-Xlint:all,-options']
98114

@@ -104,6 +120,7 @@ subprojects { subproject ->
104120
append = false
105121
destinationFile = file("$buildDir/jacoco.exec")
106122
}
123+
useJUnitPlatform()
107124
}
108125

109126
checkstyle {
@@ -202,7 +219,7 @@ project ('spring-kafka-test') {
202219
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
203220
}
204221

205-
compile ("junit:junit:$junitVersion") {
222+
compile ("junit:junit:$junit4Version") {
206223
exclude group: 'org.hamcrest', module: 'hamcrest-core'
207224
}
208225
compile ("org.mockito:mockito-core:$mockitoVersion") {

Diff for: gradle/wrapper/gradle-wrapper.jar

-398 Bytes
Binary file not shown.

Diff for: gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
34
zipStoreBase=GRADLE_USER_HOME
45
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip

Diff for: spring-kafka/src/test/java/org/springframework/kafka/core/StreamsBuilderFactoryBeanTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
import java.util.Map;
2727

2828
import org.apache.kafka.streams.StreamsConfig;
29-
import org.junit.BeforeClass;
30-
import org.junit.Test;
31-
import org.junit.runner.RunWith;
29+
import org.junit.jupiter.api.BeforeAll;
30+
import org.junit.jupiter.api.Test;
3231

3332
import org.springframework.beans.factory.annotation.Autowired;
3433
import org.springframework.beans.factory.annotation.Value;
@@ -40,13 +39,14 @@
4039
import org.springframework.kafka.test.context.EmbeddedKafka;
4140
import org.springframework.kafka.test.rule.KafkaEmbedded;
4241
import org.springframework.test.annotation.DirtiesContext;
43-
import org.springframework.test.context.junit4.SpringRunner;
42+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4443

4544
/**
4645
* @author Pawel Szymczyk
47-
* @author Artme Bilan
46+
* @author Artem Bilan
47+
* @author Gary Russell
4848
*/
49-
@RunWith(SpringRunner.class)
49+
@SpringJUnitConfig
5050
@DirtiesContext
5151
@EmbeddedKafka
5252
public class StreamsBuilderFactoryBeanTests {
@@ -55,7 +55,7 @@ public class StreamsBuilderFactoryBeanTests {
5555

5656
private static Path stateStoreDir;
5757

58-
@BeforeClass
58+
@BeforeAll
5959
public static void setup() throws IOException {
6060
stateStoreDir = Files.createTempDirectory("test-state-dir");
6161
}

0 commit comments

Comments
 (0)