【发布时间】:2018-11-12 21:05:17
【问题描述】:
我有一个类像这样实现 Runnable
public Processor implements Runnable{
public void run() {
while (true) {
//some code
sendRequest(object);
}
}
}
public void sendRequest(Object, object){
// do something to send the event
}
}
在其他预加载类中。我用
Processor processor = new Processor();
ExecutorService executor = Executors.newCachedThreadPool();
executor.execute(processor)
所以我的问题是如何单元测试 sendRequest 方法是否被调用?
【问题讨论】:
-
sendRequest 发送东西到哪里?从示例中不清楚。通常,我会注入/获取一个模拟目标,该目标可以向测试类报告成功/失败,并具有适当的超时时间。某种程度上,类似于greenmail支持邮件测试的方式。
标签: java multithreading unit-testing junit