Our project currently has two types of tests: Tests that communicate with the MySQL test database and tests that don't.
The database tests should be run in sequence as they mutate the same database, since having multiple of these tests side by side could cause concurrency issues or interference.
Currently, I have set up my Gradle in such a way that there are individual tasks for running the database tests and executing the non-database tests, and locally running these tasks individually works perfectly.
The issue is that generating a coverage report for our CI requires both, but running all tests in sequence without parallelism is extremely slow, so I want to only do this for the database tests. For this, I tried to join them in an "allTests" task.
Unfortunately, no matter what I try, I always get one of the following issues:
- The combined task is not configured as a test task, so you cannot see the individual tests in IntelliJ, and you can only see at the end whether it succeeded or passed.
- The GitHub CI fails for some reason, even though locally everything runs fine. It's not the database that is the issue, as previously I only had a single database-related test, and it worked fine. The problem arose when I added more.
I'll provide the gradle.settings.kts below in the hope that this provides insights into what is wrong or whether I completely chose the wrong path to tackle this problem.
I'm using Gradle 8.5 with a Kotlin project that uses Kover to parse Jacoco reports in the CI.
Part of my gradle.settings.kts:
tasks.register<Test>("dbTestsOnly") {
useJUnitPlatform {
includeTags("dbTest")
}
maxParallelForks = 1
systemProperty("junit.jupiter.execution.parallel.enabled", "false")
}
tasks.register<Test>("unitTestsOnly") {
useJUnitPlatform {
excludeTags("dbTest")
}
maxParallelForks = Runtime.getRuntime().availableProcessors()
systemProperty("junit.jupiter.execution.parallel.enabled", "true")
}
tasks.register<Test>("allTests") {
// Disable this task from running tests itself, but let the dependent tasks run them
useJUnitPlatform {
exclude("*")
}
dependsOn("unitTestsOnly", "dbTestsOnly")
}
tasks.named("dbTestsOnly") {
mustRunAfter("unitTestsOnly")
}
tasks.register("coverageReport") {
dependsOn("allTests", "koverHtmlReport", "koverXmlReport")
}