Skip to content
Advertisement

lateinit property mock object has not been initialized

I’m trying to initialize (by mocking) two objects with the annotation @MockBean

It seems only to work if i call the method mock(className), but since i want to use the mocked class on multiple methods i don’t want to keep repeating the same code in my test methods.

This is my test class:

JavaScript

I don’t want to use the Spring Boot @Autowired annotation because my spring application requires contexts which i don’t want to load.

The error i’m getting:

JavaScript

Dependencies:

JavaScript

Advertisement

Answer

I solved this problem by calling initMocks method in setUp()

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement