【发布时间】:2021-11-03 08:55:45
【问题描述】:
我有一个类似下面的方法:
void enact(@NonNull final Request request) {
XInput input = this.xBuilder.buildInputPayload(request);
final Thread componentThread = new Thread(()->this.component.runJob(input));
componentThread.start();
return;
}
void testVTService_Success() {
when(xBuilder.buildInputPayload(any(Request.class))).thenReturn(inputPayloadWithAllArguments);
activity.enact(TestConstants.request);
verify(component, times(1)). runJob(any(XInput.class)); //Verification
}
在验证 component.runJob() 方法正在执行时,它会抛出一个错误,指出 Wanted but not invoked: component.runJob() Actually, there were zero interactions with this mock.
我该如何解决这个问题?并验证线程是否正在启动并执行 runJob 方法?
【问题讨论】:
标签: java junit mocking mockito