Hi all, I am splitting my tests into different mod...
# dependency-management
k
Hi all, I am splitting my tests into different modules and I came across JvmTestSuite. I've added it to my build.gradle.kts. But I'm having the issue that the new JvmTestSuite does not have access to internal classes. Is it possible to get this done?
Copy code
testing {
    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.
Copy code
tasks.named<ProcessResources>("processTestResources") {
    duplicatesStrategy = DuplicatesStrategy.INCLUDE // Options: INCLUDE, WARN, EXCLUDE
}

tasks.named<ProcessResources>("processTestGraphqlResources") {
    duplicatesStrategy = DuplicatesStrategy.INCLUDE // Options: INCLUDE, WARN, EXCLUDE
}
v
As you talk about
internal
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.
e
Copy code
testing {
    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 too
👌 1
k
Thank you for the responses, I've been able to solve it with
Copy code
testing {
    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"))
}
👌 1
I found this project : https://github.com/coditory/gradle-integration-test-plugin-sample which already solved the problem, they even made a plugin, but I've opted not to use the plugin