I'm mocking a method in a class that uses the `@Au...
# mockk
d
I'm mocking a method in a class that uses the
@Autowired lateinit var x
DI pattern. I'm mocking the method exactly to avoid initializing the dependency, yet once I do
Copy code
every { myService.methodUsingX() } ...
I get
lateinit property x has not been initialized
. Is this expected?
m
i don’t know much about spring-mockk so i don’t know if it’s expected to work with @Autowired dependencies or not
but if you switch to constructor injection rather than @Autowired injection it’s still supported by spring and you can inject mocked objects in your tests
d
My bad. This test doesn't use spring-mock at all.
myService
is instatiated explicitly. And that was the problem - I forgot wrapping it with
spyk
:-)
128 Views