Skip to content

Commit

Permalink
Use jvm-test-suite and java-test-fixtures plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Chelombitko committed Dec 18, 2024
1 parent fb30a86 commit 96d43cf
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.attributes.TestSuiteType
import org.gradle.api.attributes.Usage
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.plugins.jvm.JvmTestSuite
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.tasks.GenerateModuleMetadata
import org.gradle.api.tasks.testing.Test
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.gradle.testing.base.TestingExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension

class MarathonConventionsPlugin : Plugin<Project> {
Expand All @@ -30,6 +36,8 @@ class MarathonConventionsPlugin : Plugin<Project> {

project.plugins.withId("java") {
project.plugins.apply("maven-publish")
project.plugins.apply("java-test-fixtures")
project.plugins.apply("jvm-test-suite")
project.configureJava(versionCatalog)
project.configureTesting(versionCatalog)
}
Expand Down Expand Up @@ -93,22 +101,50 @@ class MarathonConventionsPlugin : Plugin<Project> {
}
}

@Suppress("UnstableApiUsage")
private fun Project.configureTesting(versionCatalog: VersionCatalog) {
dependencies {
add("implementation", platform(versionCatalog.findLibrary("junit-bom").get()))
add("testImplementation", versionCatalog.findLibrary("mockito-kotlin").get())
add("testImplementation", versionCatalog.findLibrary("junit-jupiter-api").get())
add("testImplementation", versionCatalog.findLibrary("spek-api").get())
add("testRuntimeOnly", versionCatalog.findLibrary("junit-jupiter-engine").get())
add("testRuntimeOnly", versionCatalog.findLibrary("junit-platform-launcher").get())
add("testRuntimeOnly", versionCatalog.findLibrary("spek-engine").get())
}
extensions.configure<TestingExtension> {
suites.run {
named<JvmTestSuite>("test") {
useJUnitJupiter(versionCatalog.findVersion("junit5").get().requiredVersion)

dependencies {
implementation(versionCatalog.findLibrary("spek-api").get())
runtimeOnly(versionCatalog.findLibrary("spek-engine").get())
}
}
val integrationTest = register<JvmTestSuite>("integrationTest") {
testType.set(TestSuiteType.INTEGRATION_TEST)

tasks.withType<Test>().configureEach {
useJUnitPlatform {
includeEngines("spek", "junit-jupiter")
dependencies {
implementation(project())
implementation(testFixtures(project()))
}
}
withType<JvmTestSuite>().configureEach {
dependencies {
implementation(platform(versionCatalog.findLibrary("kotlin-bom").get()))
implementation(platform(versionCatalog.findLibrary("kotlinx-coroutines-bom").get()))
implementation(platform(versionCatalog.findLibrary("ktor-bom").get()))
implementation(platform(versionCatalog.findLibrary("junit-bom").get()))
implementation(versionCatalog.findLibrary("mockito-kotlin").get())
implementation(versionCatalog.findLibrary("junit-jupiter-api").get())
implementation(versionCatalog.findLibrary("kotlinx-coroutines-test").get())
runtimeOnly(versionCatalog.findLibrary("junit-jupiter-engine").get())
runtimeOnly(versionCatalog.findLibrary("junit-platform-launcher").get())
}
}

tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME) {
dependsOn(integrationTest)
}
}
}

dependencies {
add("testFixturesImplementation", platform(versionCatalog.findLibrary("kotlinx-coroutines-bom").get()))
add("testFixturesImplementation", platform(versionCatalog.findLibrary("ktor-bom").get()))
}
}

private fun Project.configurePublishing() {
Expand Down
41 changes: 12 additions & 29 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ plugins {
id("com.badoo.marathon.conventions")
}

sourceSets {
create("integrationTest") {
compileClasspath += sourceSets["main"].output
compileClasspath += sourceSets["test"].output
compileClasspath += configurations.testCompileClasspath.get()

runtimeClasspath += sourceSets["main"].output
runtimeClasspath += sourceSets["test"].output
runtimeClasspath += configurations.testRuntimeClasspath.get()
}
}

dependencies {
implementation(project(":report:html-report"))
implementation(project(":report:execution-timeline"))
Expand All @@ -34,24 +22,19 @@ dependencies {
api(libs.koin.core)

testImplementation(project(":vendor:vendor-test"))
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.koin.test)
testImplementation(libs.ktor.client.mock)
testImplementation(libs.testcontainers)
}

val integrationTest = task<Test>("integrationTest") {
description = "Runs integration tests."
group = JavaBasePlugin.VERIFICATION_GROUP

testClassesDirs = sourceSets["integrationTest"].output.classesDirs
classpath = sourceSets["integrationTest"].runtimeClasspath

exclude("**/resources/**")

shouldRunAfter(tasks.named("test"))
testFixturesImplementation(libs.ktor.client.core)
}

tasks.named("check") {
dependsOn(integrationTest)
testing {
suites {
val integrationTest by getting(JvmTestSuite::class) {
dependencies {
implementation(project(":vendor:vendor-test"))
implementation(libs.ktor.client.mock)
implementation(libs.testcontainers)
implementation(libs.gson)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.malinskiy.marathon.cache

import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.core.use
import java.io.ByteArrayOutputStream

class MemoryCacheService : CacheService {
Expand Down
5 changes: 0 additions & 5 deletions vendor/vendor-android/base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@ dependencies {
implementation(libs.imgscalr)
implementation(libs.jackson.annotations)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.slf4j.api)

testImplementation(project(":vendor:vendor-test"))
testImplementation(libs.koin.test)
testImplementation(libs.kotlinx.coroutines.test)
}
2 changes: 0 additions & 2 deletions vendor/vendor-android/ddmlib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ dependencies {
implementation(libs.slf4j.api)

testImplementation(project(":vendor:vendor-test"))
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.koin.test)
}
1 change: 0 additions & 1 deletion vendor/vendor-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ dependencies {
implementation(libs.jsonassert)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlin.reflect)
implementation(libs.spek.api)
}

0 comments on commit 96d43cf

Please sign in to comment.