Mockito - NullpointerException when stubbing Method

后端 未结 18 1591
半阙折子戏
半阙折子戏 2020-11-30 20:54

So I started writing tests for our Java-Spring-project.

What I use is JUnit and Mockito. It\'s said, that when I use the when()...thenReturn() option I can mock ser

18条回答
  •  失恋的感觉
    2020-11-30 21:05

    you need to initialize MockitoAnnotations.initMocks(this) method has to called to initialize annotated fields.

       @Before public void initMocks() {
           MockitoAnnotations.initMocks(this);
       }
    

    for more details see Doc

提交回复
热议问题