Unit testing Can';不要在返回时使用Mockito

Unit testing Can';不要在返回时使用Mockito,unit-testing,kotlin,mockito,Unit Testing,Kotlin,Mockito,我正在尝试编写mockitowhen方法,以便在调用方法时可以定义返回的数据。java方法: when(myRepository.insertNote(any(Note.class))).thenReturn(returnedData); 在kotlin中,我试图编写相同的代码,但它没有显示在when()之后写入thenReturn()的选项。我正在努力: when(mainRepository.fetchApiresultFromClient(ArgumentMatchers.anySt

我正在尝试编写mockitowhen方法,以便在调用方法时可以定义返回的数据。java方法:

 when(myRepository.insertNote(any(Note.class))).thenReturn(returnedData);
kotlin中,我试图编写相同的代码,但它没有显示在when()之后写入thenReturn()的选项。我正在努力:

 when(mainRepository.fetchApiresultFromClient(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(),ArgumentMatchers.anyString(), ArgumentMatchers.anyInt()) )
        .thenReturn(returnedData)

如何解决此问题?

使用
doReturn
,然后使用
when
作为最佳实践:

doReturn(returnedData).when(mainRepository)
.fetchApiresultFromClient(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(),ArgumentMatchers.anyString(), 
    ArgumentMatchers.anyInt());

谢谢你也能帮我一下吗