代码中存在异步逻辑

@Autowired
AsyncRunner asyncRunner;
...
public Result testMethod() {
    ...
    asyncRunner.submit(()->{
    // 一些异步逻辑
    });
    ...
}
如果直接测试的话,异步方法来不及执行完整。现在是粗暴地通过Thread.sleep()来测试,有没有办法能够借助mock,使得异步逻辑在测试中同步执行?
期望的方法如:

@Mock
AynscRunner asyncRunner;
...
when(asyncRunner.submit(testLogic())).callRealMethod(testLogic());
Result result = testMethod();
  • 旺盛的绿萝    2018-05-25 15:38:56
  • 阅读 1256    收藏 0    回答 1
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信