0
好吧,所以我顯然不太明白doReturn(...)。(...)和when(...)。thenReturn(...)之間的區別。DoReturn拋出UnfinishedStubbingException
事情是當我有一個類,我用@Mock註釋Mocks並在我的類中用@InjectMocks注入它們時我想測試,然後在這些模擬對象之一上使用doReturn,我得到一個UnfinishedStubbingException。但是當我使用時(...),然後返回(...)一切似乎工作得很好。我認爲doReturn是更好的建議,因爲它並沒有真正調用這個方法(我猜(...)。然後返回(...)不會,因爲這個字段是模擬的。)
所以這裏有一個例子:
doReturn(siteModel).when(siteService.getCurrentSite()) --> UnfinishedStubbingException
when(siteService.getCurrentSite()).thenReturn(siteModel) --> Works just fine