you need to annotate the test with springboottest so that spring initialize an application context
springboottest
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html#boot-features-testing-spring-boot-applications
@springboottest @runwith(springjunit4classrunner.class) public class addressservicetest { // the remaining test }
also you do not need mockitoannotations.initmocks(this);
mockitoannotations.initmocks(this);
spring takes care of the mock handling
when [@mockbean is]used on a field, the instance of the created mock will also be injected. mock beans are automatically reset after each test method
see mocking and spying beans
you need to annotate the test with
springboottest
so that spring initialize an application contexthttps://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html#boot-features-testing-spring-boot-applications
also you do not need
mockitoannotations.initmocks(this);
spring takes care of the mock handling
see mocking and spying beans