你好,我想知道什麼是最好的方法來模擬void方法,例如:我有一個PersonManager在測試下,然後我有嘲笑的道。用EasyMock和Mockito嘲笑void方法
class PersonManager {
PersonDao dao...
PersonManager(PersonDao dao)...
Preson find(String person)...
void delete(String person)...
}
class PersonManagerTest {
Map<String, Person> persons ..... = "person1", "person2", "person3";
PersonDao mock...
PersonManager manager = new PersonManager(mock);
//easy one
@Test public void shouldReturnExistingPerson() {
expect(mock.find("person1").andReturn(persons.get(0));
Person result = manager.find("person1");
// replay and verify logic
}
//but what should I do here?
@Test public void shouldDeleteExistingPerson() {
//should I remove a person from testing Map holding test data? or what am I doing wrong
}
}
所以測試方法返回很容易,但如何設置void方法?感謝您的建議,Mcokito的例子也歡迎。 }
這些答案都可以接受嗎? – 2011-05-23 10:43:19