Hello :wave::skin-tone-4: I was wondering if anyo...
# koin
h
Hello 👋🏽 I was wondering if anyone here could shed me some light and explain why I’m getting the following error:
org.koin.core.error.NoBeanDefFoundException: No definition found for class:'com.atlassian.buildeng.pipeline.compliant.checker.service.BuildInfoService'. Check your definitions!
The class that it is complaining about, it is actually an
interface
Copy code
interface BuildInfoService<T : HttpRequestParamsModel, out P> {
    suspend fun getBuildInfo(httpRequestParamsModel: T): P
}
I’m currently trying to configure my Koin test module with classes that implement that interface. In my definition, I’m adding qualifier to everything. Example:
Copy code
val testModule = module {
    ...
    single<BuildInfoService<ModelA, TypeA>>(named("BuildInfoService_A")) { MyClassA(get(named("ServiceA"))) }
    single<BuildInfoService<ModelB, TypeB>>(named("BuildInfoService_B")) { MyClassB(get(named("ServiceB")), get(named("ServiceA"))) }
    ...
}
Just to complement a bit further, the project is running
Koin = 2.2.2
and
Ktor=1.5.1
. Any help would be greatly appreciated.
t
You might use
get<BuildInfoService>()
somewhere.
h
Thanks for your reply Christian. I don’t have any usage of this.
t
BuildInfoService
might be inferred. You’re code might only contain
get()
as argument for a
BuildInfoService
parameter
h
Apologies for not having understood it yet. You are correct when it comes to
BuildInfoService
being inferred. But the classes that implement it, accept arguments, which I’m injecting. Example:
Copy code
class MyClassA(private val serviceA: ServiceA) : BuildInfoService<ModelA, TypeA>

class MyClassB(private val serviceB: ServiceB, val serviceA: ServiceA) : BuildInfoService<ModelB, TypeB>
t
How do you inject
BuildInfoService
into other classes?
h
I’m injecting
BuildInfoservice<A,B>
like this:
Copy code
single { GetBuildA(get(named("BuildInfoService_A"))) }

single { GetBuildB(get(named("BuildInfoService_B"))) }
I’m using the qualifier name.
I reckon it worth saying that I have no problem with application module, which uses pretty much the same thinking. The whole problem so far is in my
testModule
t
Then this might not be the issue. Is this ☝️ the only error you get or do you have a longer stacktrace. The exception is also thrown, when the creation of a dependency fails.
h
Indeed I have a full stacktrace.
Copy code
BitbucketBuildServiceImplTest > testShouldNotGetStepStateIfStepIdIsNotProvided() FAILED
    org.koin.core.error.NoBeanDefFoundException: No definition found for class:'com.atlassian.buildeng.pipeline.compliant.checker.service.BuildInfoService'. Check your definitions!
        at org.koin.core.scope.Scope.throwDefinitionNotFound(Scope.kt:282)
        at org.koin.core.scope.Scope.resolveInstance(Scope.kt:251)
        at org.koin.core.scope.Scope.get(Scope.kt:204)
        at service.BitbucketBuildServiceImplTest$$special$$inlined$inject$1.invoke(KoinTest.kt:54)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at service.BitbucketBuildServiceImplTest.getBuildInfoService(BitbucketBuildServiceImplTest.kt)
        at service.BitbucketBuildServiceImplTest.access$getBuildInfoService$p(BitbucketBuildServiceImplTest.kt:36)
        at service.BitbucketBuildServiceImplTest$testShouldNotGetStepStateIfStepIdIsNotProvided$1.invokeSuspend(BitbucketBuildServiceImplTest.kt:73)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:84)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
        at service.BitbucketBuildServiceImplTest.testShouldNotGetStepStateIfStepIdIsNotProvided(BitbucketBuildServiceImplTest.kt:73)
t
Are all tests failing or only some?
h
All of them with the same error
t
Then it should be an issue with the test setup. How did you attach
testModule
to your dependency graph?
h
This is the full example.
t
Found it: you’ll have to use
inject(named('...'))
for your test build info service as well.
h
Oh god, I tried that before. Let me see if works.
t
But you should consider to remove the qualifiers from your test module.
In your main module you don’t use it, thus you might run into other issues later as well.
h
Yes, I definitely should. The whole problem is that I need the qualifiers otherwise Koin won’t know which Generic Class it should expects
t
Yes. That’s an issue. True
Anyhow, good luck with your testing 🙂
h
Thank you so much for your help. 🙂 It still doesn’t seem to work. I’m going to have a look tomorrow.
What really intrigues me is that adding qualifiers change the whole behaviour of the tests. This is what is confusing me.
t
I think qualifiers replace the class as definition - at least it was like this before
h
Got it!
👍 1
Thanks heaps once again. If I figure the problem, I will make sure I post it here.
t
You’re welcome 🙂
👍 1