InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
8.98k stars 710 forks source link

Koin + JUnit 5 with parallel execution enabled #1722

Closed PowerOfCreation closed 3 months ago

PowerOfCreation commented 10 months ago

Describe the bug According to the documentation it's possible to use JUnit 5 together with Koin by using Extension: https://insert-koin.io/docs/reference/koin-test/testing/#testing-with-junit5. I followed this guide and this works as expected. When enabling parallel execution I do face issues though, as one Thread reports "KoinApplication has not been started" and the next one "A Koin Application has already been started".

To Reproduce Steps to reproduce the behavior:

  1. clone https://github.com/PowerOfCreation/KoinJUnit5ParallelExecution
  2. execute ./gradlew test

Expected behavior Both tests will run in parallel

Koin module and version: koin-core:3.4.3 koin-test:3.4.3 koin-test-junit5:3.4.3

I'm using 3.4.3 as I read 3.5.0 has issues with JUnit 5.

Snippet or Sample project to help reproduce https://github.com/PowerOfCreation/KoinJUnit5ParallelExecution

PowerOfCreation commented 10 months ago

I tried coming up with a solution myself and this seems to be working in this small dummy project, but I have still to investigate if it's actually working with an existing large project and what issues might arise. I would really appreciate some help on how to do t his properly.

This is what I came up with: https://github.com/PowerOfCreation/KoinJUnit5ParallelExecution/commit/d8875e949fcd1c64802271670fe1b4dc4f1e8de5

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.