Skip to content

Commit

Permalink
Migrate to JVM Test Suite (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Jan 11, 2025
1 parent eba1c30 commit f94417c
Show file tree
Hide file tree
Showing 35 changed files with 68 additions and 68 deletions.
134 changes: 68 additions & 66 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("UnstableApiUsage")

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

Expand Down Expand Up @@ -44,26 +46,6 @@ spotless {
}
}

val intiTest: SourceSet by sourceSets.creating
val intiTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
val intiTestRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
}

val funcTest: SourceSet by sourceSets.creating
val funcTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
val funcTestRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
}

gradlePlugin {
testSourceSets.add(funcTest)
}

dependencies {
implementation(libs.apache.ant)
implementation(libs.apache.commonsIo)
Expand All @@ -74,61 +56,81 @@ dependencies {
implementation(libs.plexus.utils)
implementation(libs.plexus.xml)

testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
testImplementation(libs.assertk)
testImplementation(libs.xmlunit)
testRuntimeOnly(libs.junit.platformLauncher)

funcTestImplementation(sourceSets.main.get().output)
funcTestImplementation(libs.apache.maven.modelBuilder)
funcTestImplementation(libs.moshi)
funcTestImplementation(libs.moshi.kotlin)

lintChecks(libs.androidx.gradlePluginLints)
}

val integrationTest by tasks.registering(Test::class) {
description = "Runs the integration tests."
group = LifecycleBasePlugin.VERIFICATION_GROUP
testClassesDirs = intiTest.output.classesDirs
classpath = intiTest.runtimeClasspath
testing.suites {
getByName<JvmTestSuite>("test") {
dependencies {
implementation(libs.xmlunit)
}
}
register<JvmTestSuite>("integrationTest") {
testType = TestSuiteType.INTEGRATION_TEST
targets.configureEach {
testTask {
val docsDir = file("src/docs")
// Add src/docs as an input directory to trigger ManualCodeSnippetTests re-run on changes.
inputs.dir(docsDir)
systemProperty("DOCS_DIR", docsDir.absolutePath)
}
}
}
register<JvmTestSuite>("functionalTest") {
testType = TestSuiteType.FUNCTIONAL_TEST
targets.configureEach {
testTask {
// Required to enable `IssueExtension` for all tests.
systemProperty("junit.jupiter.extensions.autodetection.enabled", true)

// Required to test configuration cache in tests when using withDebug()
// https://github.com/gradle/gradle/issues/22765#issuecomment-1339427241
jvmArgs(
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.util.concurrent.atomic=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens",
"java.base/java.net=ALL-UNNAMED",
)
}
}
dependencies {
// Seems we can't ref project() here due to some limitations of rootProject.
implementation(sourceSets.main.get().output)
implementation(libs.apache.ant)
implementation(libs.apache.maven.modelBuilder)
implementation(libs.moshi)
implementation(libs.moshi.kotlin)
}
}

val docsDir = file("src/docs")
// Add src/docs as an input directory to trigger ManualCodeSnippetTests re-run on changes.
inputs.dir(docsDir)
systemProperty("DOCS_DIR", docsDir.absolutePath)
withType<JvmTestSuite>().configureEach {
useJUnitJupiter(libs.junit.bom.map { requireNotNull(it.version) })
dependencies {
implementation(libs.assertk)
}
targets.configureEach {
testTask {
maxParallelForks = Runtime.getRuntime().availableProcessors()
}
}
}
}

val functionalTest by tasks.registering(Test::class) {
description = "Runs the functional tests."
group = LifecycleBasePlugin.VERIFICATION_GROUP
testClassesDirs = funcTest.output.classesDirs
classpath = funcTest.runtimeClasspath

// Required to enable `IssueExtension` for all tests.
systemProperty("junit.jupiter.extensions.autodetection.enabled", true)
gradlePlugin {
testSourceSets(
sourceSets["functionalTest"],
sourceSets["integrationTest"],
)
}

tasks.check {
dependsOn(integrationTest, functionalTest)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
maxParallelForks = Runtime.getRuntime().availableProcessors()

// Required to test configuration cache in tests when using withDebug()
// https://github.com/gradle/gradle/issues/22765#issuecomment-1339427241
jvmArgs(
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.util.concurrent.atomic=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens",
"java.base/java.net=ALL-UNNAMED",
dependsOn(
testing.suites.named("integrationTest"),
testing.suites.named("functionalTest"),
)
}

Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ androidx-gradlePluginLints = "androidx.lint:lint-gradle:1.0.0-alpha03"
ktlint = "com.pinterest.ktlint:ktlint-cli:1.5.0"

junit-bom = "org.junit:junit-bom:5.11.4"
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
junit-platformLauncher = { module = "org.junit.platform:junit-platform-launcher" }
assertk = "com.willowtreeapps.assertk:assertk:0.28.1"

[plugins]
Expand Down
File renamed without changes.

0 comments on commit f94417c

Please sign in to comment.