Dears, If I add a new SourceSet that depends on t...
# community-support
j
Dears, If I add a new SourceSet that depends on the output of the test SourceSet, does it means that gradle will always run the tests prior to building this new sourceSet ? What I'm doing:
Copy code
testing {
    suites {
        val test by getting(JvmTestSuite::class) {
            useJUnitJupiter() // JUnit 5 only
        }
        register<JvmTestSuite>("integrationTest") {
            testType = TestSuiteType.INTEGRATION_TEST
            dependencies {
                implementation(project())
            }
            // associate with main Kotlin compilation to access internal constants
            kotlin.target.compilations.named(name) {
                associateWith(kotlin.target.compilations["main"])
            }
            sources {
                kotlin {
                    srcDirs("src/integration-test/kotlin")
                    // ITs depends on Factories that are in UTs (should we move these in a shared testUtils SourceSet?)
                    compileClasspath += sourceSets.test.get().output
                    runtimeClasspath += sourceSets.test.get().output
                }
                resources {
                    srcDirs("src/integration-test/resources")
                }
            }
        }
	}
}

tasks.named("check") {
    dependsOn(testing.suites.named("integrationTest"))
}
This is because I have utility code used in both UTs in ITs, that are in the
test
sourceSet, to keep things simple. Should I move shared utility code in a third SourceSet ? I'd like to run the integrationTest only when invoking
./gradlew check
Thanks 🙏
t
This would only compile the tests, not run them.
v
Typically such shared code is better suited in the source set created using the
java-test-fixtures
plugin, to have such utility code properly separated from the actual test code.
Or manually in another source set which basically is the same, just that by default it is not shared to other project neither within the build, nor outside. But then really a source set. What you create is a test suite (which also creates a source set). But for such common code a source set would be more appropriate than a full-fledged tests suite
j
Ok, not sure about the java-test-fixtures plugin, does it support kotlin code, as this is a kotlin project? Anyway I think I'll go with a test-utils Sourceset that both the
test
and
integrationTest
suites will depend on. Thanks!
v
Should support Kotlin I think, yes. It mainly also just configures another source set and configures it to be published as variant if you don't disable it. But as Kotlin is just adding a language source set to all source sets it should just work fine.
Maybe not if KMP comes into play, I don't know. 🤷‍♂️
j
mkay my bad, the test suite integrationTest registers a task named
integrationTest
to run the IT, Standard task
check
already runs the default
test
task, and my config added a dependency to task
integrationTest
Now I understand why it always ran both the UT and the IT. Thanks guys, sorry for the noise 😇
👌 1