我正在尝试测试以下类(我已经省略了实现)
public class UTRI implements UTR {
public void runAsUser(String userId, Runnable r);
}
这是我使用它的方式:
UTRI.runAsUser("User1", new Runnable () {
private void run() {
//do whatever needs to be done here.
}
});
问题是,我不知道如何使用EasyMock来测试返回void的函数。那个和我一般都不太熟悉测试(刚出校!)。有人可以帮我解释一下我需要做些什么来解决这个问题吗?我正在考虑让UTRI成为模拟器并在此之后进行预期调用,但实际上,不确定。
答案 0 :(得分:0)
public class UTRITest {
UTRI utri = new UTRI();
@Test
public void testRunAsUser() {
// Create Mocks
Runnable mockRunnable = EasyMock.createMock(Runnable.class);
// Set Expectations
**mockRunnable.run();
EasyMock.expectLastCall().once();**
EasyMock.replay(mockRunnable);
// Call the method under test
utri.runAsUser("RAMBO", **mockRunnable**);
// Verify if run was called on Runnable!!
EasyMock.verify(mockRunnable);
}
}