diff --git a/buildSrc/src/main/kotlin/com/badoo/marathon/conventions/MarathonConventionsPlugin.kt b/buildSrc/src/main/kotlin/com/badoo/marathon/conventions/MarathonConventionsPlugin.kt index 48cc18a22..b44ce0941 100644 --- a/buildSrc/src/main/kotlin/com/badoo/marathon/conventions/MarathonConventionsPlugin.kt +++ b/buildSrc/src/main/kotlin/com/badoo/marathon/conventions/MarathonConventionsPlugin.kt @@ -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 { @@ -30,6 +36,8 @@ class MarathonConventionsPlugin : Plugin { 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) } @@ -93,22 +101,50 @@ class MarathonConventionsPlugin : Plugin { } } + @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 { + suites.run { + named("test") { + useJUnitJupiter(versionCatalog.findVersion("junit5").get().requiredVersion) + + dependencies { + implementation(versionCatalog.findLibrary("spek-api").get()) + runtimeOnly(versionCatalog.findLibrary("spek-engine").get()) + } + } + val integrationTest = register("integrationTest") { + testType.set(TestSuiteType.INTEGRATION_TEST) - tasks.withType().configureEach { - useJUnitPlatform { - includeEngines("spek", "junit-jupiter") + dependencies { + implementation(project()) + implementation(testFixtures(project())) + } + } + withType().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() { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index f67f41fea..6a22dcdb2 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -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")) @@ -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("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) + } + } + } } diff --git a/core/src/test/kotlin/com/malinskiy/marathon/cache/MemoryCacheService.kt b/core/src/testFixtures/kotlin/com/malinskiy/marathon/cache/MemoryCacheService.kt similarity index 96% rename from core/src/test/kotlin/com/malinskiy/marathon/cache/MemoryCacheService.kt rename to core/src/testFixtures/kotlin/com/malinskiy/marathon/cache/MemoryCacheService.kt index 9bf1bc0ff..d3a6cb32a 100644 --- a/core/src/test/kotlin/com/malinskiy/marathon/cache/MemoryCacheService.kt +++ b/core/src/testFixtures/kotlin/com/malinskiy/marathon/cache/MemoryCacheService.kt @@ -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 { diff --git a/core/src/test/kotlin/com/malinskiy/marathon/cache/SimpleCacheKey.kt b/core/src/testFixtures/kotlin/com/malinskiy/marathon/cache/SimpleCacheKey.kt similarity index 100% rename from core/src/test/kotlin/com/malinskiy/marathon/cache/SimpleCacheKey.kt rename to core/src/testFixtures/kotlin/com/malinskiy/marathon/cache/SimpleCacheKey.kt diff --git a/core/src/test/kotlin/com/malinskiy/marathon/cache/SimpleEntryReader.kt b/core/src/testFixtures/kotlin/com/malinskiy/marathon/cache/SimpleEntryReader.kt similarity index 100% rename from core/src/test/kotlin/com/malinskiy/marathon/cache/SimpleEntryReader.kt rename to core/src/testFixtures/kotlin/com/malinskiy/marathon/cache/SimpleEntryReader.kt diff --git a/core/src/test/kotlin/com/malinskiy/marathon/cache/SimpleEntryWriter.kt b/core/src/testFixtures/kotlin/com/malinskiy/marathon/cache/SimpleEntryWriter.kt similarity index 100% rename from core/src/test/kotlin/com/malinskiy/marathon/cache/SimpleEntryWriter.kt rename to core/src/testFixtures/kotlin/com/malinskiy/marathon/cache/SimpleEntryWriter.kt diff --git a/vendor/vendor-android/base/build.gradle.kts b/vendor/vendor-android/base/build.gradle.kts index dce593010..4e989f6db 100644 --- a/vendor/vendor-android/base/build.gradle.kts +++ b/vendor/vendor-android/base/build.gradle.kts @@ -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) } diff --git a/vendor/vendor-android/ddmlib/build.gradle.kts b/vendor/vendor-android/ddmlib/build.gradle.kts index adf7728fc..616fc5061 100644 --- a/vendor/vendor-android/ddmlib/build.gradle.kts +++ b/vendor/vendor-android/ddmlib/build.gradle.kts @@ -18,6 +18,4 @@ dependencies { implementation(libs.slf4j.api) testImplementation(project(":vendor:vendor-test")) - testImplementation(libs.kotlinx.coroutines.test) - testImplementation(libs.koin.test) } diff --git a/vendor/vendor-test/build.gradle.kts b/vendor/vendor-test/build.gradle.kts index cb7436f8a..ceb441fca 100644 --- a/vendor/vendor-test/build.gradle.kts +++ b/vendor/vendor-test/build.gradle.kts @@ -8,5 +8,4 @@ dependencies { implementation(libs.jsonassert) implementation(libs.kotlinx.coroutines.core) implementation(libs.kotlin.reflect) - implementation(libs.spek.api) }