InsertKoinIO / koin

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

Can't use the `verify()` test function on my main :app module when I need to ignore some types that are part of my sub-modules and have internal modifier #1573

Open StylianosGakis opened 1 year ago

StylianosGakis commented 1 year ago

Is your feature request related to a problem? Please describe. I am trying to incorporate the verify() test task in my unit tests to ensure that my graph is correct. When doing so, I've figured out that the types that are not part of the graph but I rely on the call-site to provide them using parametersOf() need to be ignored by this task but passing them as a list to the verify function. However, this is impossible for types that are only present in modules and are internal to those modules by default.

Describe the solution you'd like I am not sure what a solution would look like. but there's definitely other folks who have a similar setup and I am curious what steps they've taken to get this work for me.

Describe alternatives you've considered I could potentially create a list of Class<*> inside each module which has this problem, and expose that publicly so that this test would be able to get it per-module and add it to this list of ignored classes, but this certainly feels like quite a lot of ceremony. Is this what I should be doing in this case? And I worry that this would be misused by other callers of that module. Maybe this list of classes can exist only in the test directory.

Target Koin project The testing artifact

arnaudgiuliani commented 1 year ago

Yep, still a limitation of verify() API. Work in progress on it, to help make it better

arnaudgiuliani commented 1 year ago

after works around, this impact more the internal design to let open things. The idea is to find the best way to have kindof sandbox running if possible. Else Koin Annotations will bring compile safety more completely since 1.3.0.

StylianosGakis commented 1 year ago

Hey Arnaud, I am not sure I follow, is there some workaround in the latest koin versions on how to achieve this now? Or do you suggest that with 1.3.0 and by using annotation based setup you'll be able to do this in a simple way?

JajaComp commented 5 months ago

You can check this pull reuest - https://github.com/InsertKoinIO/koin/pull/1854

StylianosGakis commented 5 months ago

While that works, it's so much manual setup that I am not even sure it's worth the effort of maintaining it forever, while also making sure to remove the names of the ones that may no longer be relevant