Christian Hujer
04/02/2024, 2:25 PMlib-tests/src/main/kotlin/org/example/ReusableTest.kt
app-impl1/
app-impl2/
In the dependencies {}
in build.gradle.kts
of app-impl1/
and app-impl2/
I have testImplementation(project(":lib-tests"))
.
The purpose is, as I hope is obvious from the structure, to have the tests from lib-tests/
run for both apps.
However, the tests are not run.
I'm using Gradle 8.7, Java 21, Kotlin 1.9.23, JUnit Platform 5.10.2.
Where can I find more documentation on how Gradle discovers tests so that I can get this running?
(Note that for feature files in Cucumber running as JUnit extension, this setup works just fine, pulling them in from lib-tests/src/main/resources/features
.)Thomas Broyer
04/02/2024, 2:32 PMTest
task only looks at its testClassesDirs
property for where to find test classes (https://docs.gradle.org/current/userguide/java_testing.html#sec:java_testing_basics), so if the test classes come from another project I suppose you'd have to first copy/extract them into a directory you can configure as testClassesDirs
.Christian Hujer
04/02/2024, 2:36 PM../lib-tests/build/classes/kotlin/main
to testClassesDirs
should do the trick?Christian Hujer
04/02/2024, 2:42 PMtasks.withType<Test> {
useJUnitPlatform()
testClassesDirs = testClassesDirs.plus(files("../lib-tests/build/classes/kotlin/main"))
}
Is there a nicer way to do that? It doesn't feel right to me to hardcode the path to the build outputs of another module.Christian Hujer
04/02/2024, 2:48 PMThomas Broyer
04/02/2024, 2:48 PMclasses
variant (ask for the libraryelements=classes attribute, maybe also add artifact-type=directory) and non-transitive, add project(":lib-tests")
as a dependency to that configuration, then add the configuration to the testClassesDirs
.Thomas Broyer
04/02/2024, 2:50 PMtestImplementation
dependency as well)