如何使用的Junit测试异步进程 [英] How to use Junit to test asynchronous processes

查看:1870
本文介绍了如何使用的Junit测试异步进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么测试火异步进程使用JUnit的方法呢?

How do you test methods that fire asynchronous processes with Junit?

我不知道如何让我的测试等待进程结束(它不完全是一个单元测试,它更像是一个集成测试,因为它涉及几类,而不是只有一个)

I don't know how to make my test wait for the process to end (it is not exactly a unit test, it is more like an integration test as it involves several classes and not just one)

推荐答案

恕我直言是不好的做法有单元测试创​​建或等待的线程,等你想这些测试在斯普利特秒运行。这就是为什么我想提出一个2步的方法来测试异步进程。

IMHO it's bad practice to have unit tests create or wait on threads, etc. You'd like these tests to run in split seconds. That's why I'd like to propose a 2-step approach to testing async processes.


  1. 测试你的异步进程正确提交。你可以嘲笑接受你的请求,异步的目标,并确保所提交的工作有正确的属性,等等。

  2. 测试你的异步回调做正确的事。在这里,你可以模拟出最初提交的作业,并承担它的正常初始化,验证您的回调是正确的。

这篇关于如何使用的Junit测试异步进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆