I am writing JUnit test cases for a method which uses executor service. I want to test the flow with the background task getting completed. I can only do it if I stub or write an executor service which will use main thread itself to do the task execution. But I could not find such option in Java ExecutorService code. It looks common problem to me. Has anyone done it yet & have any sample code to share?