我正在使用Mockito編寫簡單的單元測試。Mockito:將模擬對象作爲參數傳遞給函數(調用函數時)
我有一個功能測試:
public void doSomething() {
foo.getStudent(new School());
}
我的測試用例:
@Test
public void testDoSomething() {
Foo mockedFoo = Mockito.mock(Foo.class);
School mockedSchool = Mockito.mock(School.class);
// I want to pass the mocked school as parameter when food.getStudent(school) is called
// how to pass mocked school to method?
when(mockedFoo.getStudent(???))
// run the method under test
myService.doSomething();
}
我想通過mockedSchool
作爲參數時foo.getStudent(school)
被調用時,如何在聲明的Mockito這個?
似乎Mockito只有when(...).thenReturn()
,但有沒有像when(...).thenPassArgument(mockedObject)
?
這兩個鏈接都死了,請你更新。 –