Skip to content

Commit 85444a9

Browse files
authored
Migrate to JUnit5 test runner with vintage test engine (#3012)
1 parent fb4ad38 commit 85444a9

File tree

12 files changed

+137
-18
lines changed

12 files changed

+137
-18
lines changed

buildSrc/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ dependencies {
2929
testImplementation(deps.assertj)
3030
testImplementation(deps.junit4)
3131
testImplementation(deps.bundles.mockito)
32+
33+
testRuntimeOnly(deps.junit5.jupiterVintage)
34+
}
35+
36+
tasks.test {
37+
useJUnitPlatform()
3238
}

buildSrc/src/main/kotlin/toolkit-intellij-subplugin.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ configurations {
5757
// Exclude dependencies we don't use to make plugin smaller
5858
exclude(group = "software.amazon.awssdk", module = "netty-nio-client")
5959
}
60+
61+
// TODO: https://github.com/gradle/gradle/issues/15383
62+
val versionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
63+
dependencies {
64+
testImplementation(platform(versionCatalog.findDependency("junit5-bom").get()))
65+
testImplementation(versionCatalog.findDependency("junit5-jupiterApi").get())
66+
67+
testRuntimeOnly(versionCatalog.findDependency("junit5-jupiterEngine").get())
68+
testRuntimeOnly(versionCatalog.findDependency("junit5-jupiterVintage").get())
69+
}
6070
}
6171

6272
tasks.processResources {
@@ -127,6 +137,8 @@ tasks.withType<Test>().all {
127137
// FIX_WHEN_MIN_IS_221: log4j 1.2 removed in 221
128138
systemProperty("log4j.configuration", jetbrainsCoreTestResources.resolve("log4j.xml"))
129139
systemProperty("idea.log.config.properties.file", jetbrainsCoreTestResources.resolve("toolkit-test-log.properties"))
140+
141+
useJUnitPlatform()
130142
}
131143

132144
tasks.withType<JavaExec> {

core/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@ dependencies {
2222
api(libs.bundles.jackson)
2323

2424
testImplementation(libs.junit4)
25+
26+
testRuntimeOnly(libs.junit5.jupiterVintage)
27+
}
28+
29+
tasks.test {
30+
useJUnitPlatform()
2531
}

detekt-rules/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ plugins {
88

99
dependencies {
1010
compileOnly(libs.detekt.api)
11+
1112
testImplementation(libs.detekt.test)
1213
testImplementation(libs.junit4)
1314
testImplementation(libs.assertj)
15+
1416
testRuntimeOnly(libs.slf4j.api)
17+
testRuntimeOnly(libs.junit5.jupiterVintage)
18+
}
19+
20+
tasks.test {
21+
useJUnitPlatform()
1522
}

gradle/libs.versions.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ intellijRemoteRobot = "0.11.11"
99
jackson = "2.11.1"
1010
jacoco = "0.8.7"
1111
jgit = "5.11.0.202103091610-r"
12-
junit4 = "4.13.1"
13-
junit5 = "5.6.2"
12+
junit4 = "4.13.2"
13+
junit5 = "5.8.2"
1414
kotlin = "1.6.10"
1515
kotlinCoroutines = "1.3.9"
1616
mockito = "4.0.0"
@@ -68,8 +68,10 @@ jackson-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-y
6868
jacoco = { module = "org.jacoco:org.jacoco.core", version.ref = "jacoco" }
6969
jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "jgit" }
7070
junit4 = { module = "junit:junit", version.ref = "junit4" }
71-
junit5-jupiterApi = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit5" }
72-
junit5-jupiterEngione = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" }
71+
junit5-bom = { module = "org.junit:junit-bom", version.ref = "junit5" }
72+
junit5-jupiterApi = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" }
73+
junit5-jupiterEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit5" }
74+
junit5-jupiterVintage = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit5" }
7375
kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinCoroutines" }
7476
kotlin-coroutinesDebug = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-debug", version.ref = "kotlinCoroutines" }
7577
kotlin-coroutinesTest = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinCoroutines" }

jetbrains-core/detekt-baseline-test.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@
118118
<ID>UnsafeCallOnNullableType:JavaTestUtils.kt$psiFile.classes[0].allMethods[0].body!!</ID>
119119
<ID>UnsafeCallOnNullableType:LambdaRunLineMarkerContributorTest.kt$LambdaRunLineMarkerContributorTest$it!!</ID>
120120
<ID>UnsafeCallOnNullableType:LocalLambdaRunConfigurationTest.kt$LocalLambdaRunConfigurationTest$PsiDocumentManager.getInstance(projectRule.project).getDocument(eventFile)!!</ID>
121-
<ID>UnsafeCallOnNullableType:MockResourceCache.kt$MockResourceCacheRule$connectionManager.selectedCredentialIdentifier!!</ID>
122-
<ID>UnsafeCallOnNullableType:MockResourceCache.kt$MockResourceCacheRule$connectionManager.selectedRegion!!</ID>
121+
<ID>UnsafeCallOnNullableType:MockResourceCache.kt$MockResourceCacheInterface$connectionManager.selectedCredentialIdentifier!!</ID>
122+
<ID>UnsafeCallOnNullableType:MockResourceCache.kt$MockResourceCacheInterface$connectionManager.selectedRegion!!</ID>
123123
<ID>UnsafeCallOnNullableType:ProfileCredentialProviderFactoryTest.kt$ProfileCredentialProviderFactoryTest$LocalFileSystem.getInstance().findFileByIoFile(profileFile)!!</ID>
124124
<ID>UnsafeCallOnNullableType:ProfileCredentialProviderFactoryTest.kt$ProfileCredentialProviderFactoryTest$LocalFileSystem.getInstance().refreshAndFindFileByIoFile(this)!!</ID>
125125
<ID>UnsafeCallOnNullableType:PythonCodeInsightTestFixtureRule.kt$PythonCodeInsightTestFixtureRule$newFixture.tempDirFixture.getFile(".")!!</ID>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.testFramework
5+
6+
import com.intellij.openapi.diagnostic.Logger
7+
import com.intellij.testFramework.ProjectRule
8+
import com.intellij.testFramework.TestApplicationManager
9+
import com.intellij.testFramework.TestLoggerFactory
10+
import org.junit.jupiter.api.extension.AfterAllCallback
11+
import org.junit.jupiter.api.extension.AfterEachCallback
12+
import org.junit.jupiter.api.extension.BeforeAllCallback
13+
import org.junit.jupiter.api.extension.BeforeEachCallback
14+
import org.junit.jupiter.api.extension.ExtensionContext
15+
16+
// FIX_WHEN_MIN_IS_221: junit5 Extensions available in 221
17+
// https://github.com/JetBrains/intellij-community/blob/12f2d090e59966f8395f2307182b61cf6bb66184/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt#L82
18+
open class ApplicationExtension : BeforeAllCallback, AfterAllCallback {
19+
companion object {
20+
init {
21+
Logger.setFactory(TestLoggerFactory::class.java)
22+
}
23+
}
24+
25+
override fun beforeAll(context: ExtensionContext) {
26+
TestApplicationManager.getInstance()
27+
}
28+
29+
override fun afterAll(context: ExtensionContext) {}
30+
}
31+
32+
class ProjectExtension : BeforeEachCallback, AfterEachCallback {
33+
private val rule by lazy { ProjectRule.createStandalone() }
34+
35+
override fun beforeEach(context: ExtensionContext) {
36+
rule
37+
}
38+
39+
override fun afterEach(context: ExtensionContext) {
40+
rule.close()
41+
}
42+
43+
val project = rule.project
44+
val module = rule.module
45+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.testFramework
5+
6+
// FIX_WHEN_MIN_IS_221: junit5 Extensions available in 221
7+
typealias ApplicationExtension = com.intellij.testFramework.ApplicationExtension
8+
typealias ProjectExtension = com.intellij.testFramework.ProjectExtension

jetbrains-core/tst/software/aws/toolkits/jetbrains/core/MockResourceCache.kt

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import com.intellij.openapi.components.service
88
import com.intellij.openapi.project.Project
99
import com.intellij.testFramework.ApplicationRule
1010
import kotlinx.coroutines.runBlocking
11+
import org.junit.jupiter.api.extension.AfterEachCallback
12+
import org.junit.jupiter.api.extension.BeforeEachCallback
13+
import org.junit.jupiter.api.extension.ExtensionContext
14+
import org.junit.runner.Description
1115
import software.aws.toolkits.core.ConnectionSettings
1216
import software.aws.toolkits.core.credentials.ToolkitCredentialsProvider
1317
import software.aws.toolkits.core.region.AwsRegion
@@ -99,12 +103,30 @@ class MockResourceCache : AwsResourceCache {
99103
}
100104
}
101105

102-
class MockResourceCacheRule : ApplicationRule() {
103-
private val cache by lazy { MockResourceCache.getInstance() }
106+
class MockResourceCacheRule : ApplicationRule(), MockResourceCacheInterface by MockResourceCacheInterface.delegate() {
107+
public override fun before(description: Description) {
108+
super.before(description)
109+
}
104110

105-
override fun after() {
111+
public override fun after() {
106112
runBlocking { cache.clear() }
107113
}
114+
}
115+
116+
class MockResourceCacheExtension : BeforeEachCallback, AfterEachCallback, MockResourceCacheInterface by MockResourceCacheInterface.delegate() {
117+
private val rule = MockResourceCacheRule()
118+
119+
override fun beforeEach(context: ExtensionContext) {
120+
rule.before(Description.EMPTY)
121+
}
122+
123+
override fun afterEach(context: ExtensionContext) {
124+
rule.after()
125+
}
126+
}
127+
128+
interface MockResourceCacheInterface {
129+
val cache: MockResourceCache
108130

109131
fun addEntry(resourceId: String, regionId: String, credentialsId: String, value: Any) {
110132
cache.addEntry(resourceId, regionId, credentialsId, value)
@@ -145,4 +167,10 @@ class MockResourceCacheRule : ApplicationRule() {
145167
}
146168

147169
fun size() = cache.entryCount()
170+
171+
companion object {
172+
fun delegate() = object : MockResourceCacheInterface {
173+
override val cache by lazy { MockResourceCache.getInstance() }
174+
}
175+
}
148176
}

jetbrains-ultimate/tst/software/aws/toolkits/jetbrains/services/redshift/RedshiftUtilsTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33

44
package software.aws.toolkits.jetbrains.services.redshift
55

6-
import com.intellij.testFramework.ProjectRule
76
import org.assertj.core.api.Assertions.assertThat
8-
import org.junit.Rule
9-
import org.junit.Test
7+
import org.junit.jupiter.api.Test
8+
import org.junit.jupiter.api.extension.RegisterExtension
109
import org.mockito.kotlin.doReturn
1110
import org.mockito.kotlin.mock
1211
import software.amazon.awssdk.services.redshift.model.Cluster
1312
import software.aws.toolkits.core.utils.RuleUtils
14-
import software.aws.toolkits.jetbrains.core.MockResourceCacheRule
13+
import software.aws.toolkits.jetbrains.core.MockResourceCacheExtension
1514
import software.aws.toolkits.jetbrains.core.region.getDefaultRegion
1615
import software.aws.toolkits.jetbrains.services.sts.StsResources
16+
import software.aws.toolkits.jetbrains.testFramework.ProjectExtension
1717

1818
class RedshiftUtilsTest {
1919
@JvmField
20-
@Rule
21-
val projectRule = ProjectRule()
20+
@RegisterExtension
21+
val projectRule = ProjectExtension()
2222

2323
@JvmField
24-
@Rule
25-
val resourceCache = MockResourceCacheRule()
24+
@RegisterExtension
25+
val resourceCache = MockResourceCacheExtension()
2626

2727
private val clusterId = RuleUtils.randomName()
2828
private val accountId = RuleUtils.randomName()

0 commit comments

Comments
 (0)