kris
04/02/2025, 12:10 AMtesting {
suites {
// Configure the default test suite (unit tests)
val test by getting(JvmTestSuite::class) {
useJUnitJupiter()
}
// Register an integration test suite
register<JvmTestSuite>("testGraphql") {
// Define test sources directories
sources {
kotlin {
srcDir("src/testGraphql/kotlin")
}
resources {
srcDir("src/testGraphql/resources")
}
}
dependencies {
implementation(project())
}
// Configure the implementation configuration to extend from the main implementation
configurations {
// Make testGraphqlImplementation extend from implementation
named(sources.implementationConfigurationName) {
extendsFrom(configurations["implementation"])
// Also extend from testImplementation to get all test dependencies
extendsFrom(configurations["testImplementation"])
}
// Make testGraphqlRuntimeOnly extend from runtimeOnly
named(sources.runtimeOnlyConfigurationName) {
extendsFrom(configurations["runtimeOnly"])
extendsFrom(configurations["testRuntimeOnly"])
}
}
// Test framework
useJUnitJupiter()
targets {
all {
testTask.configure {
// Make integration tests run after unit tests
shouldRunAfter(test)
// Only run tests if they've changed
outputs.upToDateWhen { false }
}
}
}
}
}
}
tasks.named("check") {
dependsOn(testing.suites.named("testGraphql"))
}
tasks.withType<Test> {
useJUnitPlatform()
}
Also I was having an issue where I have some duplicate test resources, I have solved it with this. but ideally I wouldn't need a duplicate strategy, it would just not put the the resources from a different jvmtestsuite on the classpath, that way they are seperate but can exist in the same project, but I don't know how to arrange this.
tasks.named<ProcessResources>("processTestResources") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE // Options: INCLUDE, WARN, EXCLUDE
}
tasks.named<ProcessResources>("processTestGraphqlResources") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE // Options: INCLUDE, WARN, EXCLUDE
}Vampire
04/02/2025, 2:44 AMinternal I guess you talk about Kotlin.
In that case, this seems to be a quite Kotlin-specific question and might be better suited for #gradle on the Kotlin Slack maybe.
But you can also search the Slack archives on Linen and YouTrack, I think there were discussions about this before and how to configure the "friend modules" so that the test classes can see the internal production classes. Dunno whether the KGP in the meantime got some convenient option for that.
Regarding the duplicates strategy, yes. Usually if you "need" one you actually have a different problem, namely why you have a duplicate problem at all. Setting the strategy in 98.7% of the cases is the wrong thing to do.ephemient
04/02/2025, 4:48 AMtesting {
suites {
register<JvmTestSuite>("testGraphql") {
kotlin.target.compilations.named(name) {
associateWith(kotlin.target.compilations["main"]
and you shouldn't need the extendsFrom, that's probably what's causing your duplicate resources tookris
04/02/2025, 8:55 AMtesting {
suites {
withType<JvmTestSuite> {
useJUnitJupiter()
targets.configureEach {
testTask {
testLogging {
events("passed", "failed", "skipped")
setExceptionFormat("full")
}
}
}
}
val test by getting(JvmTestSuite::class)
val testGraphql by registering(JvmTestSuite::class) {
dependencies {
implementation(project())
}
sourceSets {
named("testGraphql") {
// Don't inherit resources from the test sourceSet to avoid Flyway script conflicts
resources {
setSrcDirs(listOf("src/testGraphql/resources"))
}
}
}
kotlin.target.compilations.named("testGraphql") {
associateWith(kotlin.target.compilations["test"])
}
targets.all {
testTask.configure {
shouldRunAfter(test)
}
}
}
}
}
val testGraphqlImplementation by configurations
tasks.named("check") {
dependsOn(testing.suites.named("testGraphql"))
}kris
04/02/2025, 8:56 AM