Damian Kapłon
Damian Kapłon

Reputation: 85

Quarkus + kotlin dependency injection in tests

I am working on my quarkus + kotlin application. Having class:

@ApplicationScoped
class ParrallerCronScheduler(private val someService: SomeService) : CronScheduler

When the application is running there is no problem, quarkus injects someService. However, running this tests class:

@QuarkusTest
@QuarkusTestResource(PostgresResource::class)
internal class CroneUpdateTest(private val someService: SomeService): BaseIntegrationTest()

makes quarkus throw: When using constructor injection in a test, the only legal operation is to assign the constructor values to fields. Offending class is class com.tui.promotion_campaigns_service.services.impl.CroneUpdateTes which forces to use this imo ugly thing in tests:

@Inject
lateinit var someService: SomeService

Why the first way of test implementation not working? Is it possible to make it work?

I tried

class ParrallerCronScheduler @Inject constructor(private val someService: SomeService) : CronScheduler

Upvotes: 4

Views: 456

Answers (1)

hfc
hfc

Reputation: 788

This is a known issue in Quarkus, you can follow it here

As mentioned in the issue, seems to be caused by how JUnit works.

Upvotes: 0

Related Questions