Hello I have some difficulties with my tests and ...
# multiplatform
d
Hello I have some difficulties with my tests and maybe you have some advices or solutions. My project is using Kotlin Multiplatform and has several modules. However, to execute my tests, I need to run a docker compose first. In this dockerfile, I have a Vault (Hashicorp) and a Keycloak. Each test file, when finished, clean the Vault to remove all modified data inserted during the tests. And my problem is here. When running the command
allTests
Gradle will execute JsTest, JvmTest, LinuxTest etc. In parallel. Consequently, the Vault server is clean by the file A during the test of the file B (consequently, the tests fail) Also, when running only
jvmTest
, Gradle will execute in parallel the task by module, then the same effect is visible. My questions are: • Do you know how can I force Gradle to run tests sequentially (parallel option or maxFork doesn't work in multiplatform + multimodules) • Is there a way to use
testcontainers
in multiplatform? (That could be the best solution, but nothing was built for Kotlin, so if you have an example, that could be nice)
h
You can force Gradle to run all tasks sequentially via a Build Service, but I would write a Gradle task that starts a new container instance for each test instead (using testcontsiner), if starting the container is fast.
d
Do you have an example to do something like that? That could help a lot
c
You can force tasks to run sequentially with
mustRunAfter
, but yeah a testcontainer would be much better. The more platforms you have the more painful it is if they're not parallel
Alternatively, a much cheaper solution: have each test generate a random ID, and use that to access the vault. This way, two tests running in parallel access different data and never conflict. This lets you enable test-level parallelism, which make test suites even faster.
➕ 1
d
For the random ID, the problem is that the after each clear entirely Vault. To be sure to not let data, so.. that's not possible
And for the Gradle plugin, it starts once or for each test task? (One for jvm, one for native, one for js, etc.)? This is not written in the documentation @CLOVIS
Currently I'm using a docker compose. So ok it's not automatic, but it seems to do the same thing 🤔
c
To use the plugin, you'd have to declare one container for each platform, and add
usesService(…)
to each test task of each platform. This way, each platform runs independently. But yeah you could do the same in docker-compose with x containers