Skip to content

The "verify" api test should not replace "checkModules" yet #2300

@otazmoreira

Description

@otazmoreira

Describe the bug
The verify api test is not covering a test scenario that checkModules already covers. When a bean definition depends on a provider definition, the verify do not checks if the provider definition really exist because this test API relies on reflection, and checks only the constructors. The verify it's creating a false-positive test.

To Reproduce
Steps to reproduce the behavior:

  1. Create a class that provides other instance with a method.
  2. Do not define the provider, only the other class by the provider method.
  3. Uses get() to request the provider definition to koin and use the method to request a definition.
  4. Create a test using verify in the module.

Expected behavior
The test should fail because there's not a bean definition of the provider class, but the test will pass. That way, proving that verify creates a false-positive test.

Koin module and version:
[e.g]: koin-test:3.3.x

The problem still happening on the latest version koin-test:4.1.0.

Snippet or Sample project to help reproduce

I'have added some tests scenarios on Verification class in koin-test module to validate. This test fail because don't throw anything. Follow the sample:

@Test
fun `verify instance provided by other definition - fail`() {
    val modules = module {
        single<Simple.ComponentToBeProvided> {
            get<Simple.ComponentProvider>().getComponent()
        }
    }

    try {
        modules.verify()
       fail()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

Why "verify" should not replace "checkModules"?
I have try to solve this problem in a simple way, but I couldn't find any simple solution. CheckModules API should not be deprecated since "verify" isn't covering that import case. This case is very common to create API instances by Retrofit or DAO with Room in Android apps.

The only option that I find it was create a mock of Scope and try to execute the bean definition, and verify all the get() calls, but this will make verify works like the checkModules. Or really would be an interesting solution?

Also, the main point to verify not replace checkModules it's because koin it's a multplatform library, and since verify relies on reflection that is only available to jvm, deprecate the only option to the others platform without provide a substitute may be a problem in the future.

I couldn't figure out a way to use verify in the other platforms, not without majores changes in koin ecosystem. If already exists plans to solve that question, I would love to know about it.

Suggestion to this issue
Remove the deprecation of checkModules and keep verify as a second option, at least until verify isn't ready.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions