How to use JUnit to test asynchronous processes?

Posted by Andre Scott | Updated on

Want to use JUnit to test asynchronous processes? 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.

Test that your async process is submitted properly. You can mock the object that accepts your async requests and make sure that the submitted job has correct properties, etc.
Test that your async callbacks are doing the right things. Here you can mock out the originally submitted job and assume it’s initialized properly and verify that your callbacks are correct.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers