0
我有以下方法在我Java
服務類測試:如何停止在Mockito的另一個類中調用方法?
public void findPersonToDelete(String id){
//repository method then called
personRepository.findPersonAndDelete(id);
}
的問題是,personRepository調用它拋出一個Null Pointer
其他代碼。
我嘗試使用下面的行從調用其他方法停止personRepository:
Mockito.doNothing().when(personRepository).findPersonAndDelete(id);
但錯誤依然堅持?我怎樣才能解決這個問題?
如果你不與任何價值'id',它會正常執行的方法調用它。 – byxor
personRepository是一個模擬嗎? – Heisenberg
嘗試'anyInt()'而不是特定的值。進一步的'PersonRepository'需要是'mock'或'spy'。 –