相关疑难解决方法(0)

使用Mockito多次调用具有相同参数的相同方法

有没有办法让stubbed方法在后续调用中返回不同的对象?我想这样做来测试一个非确定的响应ExecutorCompletionService.即,无论方法的返回顺序如何进行测试,结果都保持不变.

我想要测试的代码看起来像这样.

// Create an completion service so we can group these tasks together
ExecutorCompletionService<T> completionService =
        new ExecutorCompletionService<T>(service);

// Add all these tasks to the completion service
for (Callable<T> t : ts)
    completionService.submit(request);

// As an when each call finished, add it to the response set.
for (int i = 0; i < calls.size(); i ++) {
    try {
        T t = completionService.take().get();
        // do some stuff that I want to test
    } catch (...) { } …
Run Code Online (Sandbox Code Playgroud)

java mocking mockito

254
推荐指数
6
解决办法
20万
查看次数

标签 统计

java ×1

mocking ×1

mockito ×1