But in reality, what you would really like to do is to get rid of the threads just for the testing. If you are using an Executor, it is not complicated to replace it with another one that executes the task in the current thread:
Since we are using Java 8 (at least) and Executor is a functional interface, we can revert to use a lambda:Executor forTest = new Executor() {public void execute(Runnable command) {command.run();}};
And even better to use method reference:Executor forTest = command -> command.run;
Executor forTest = Runnable::run;
No comments:
Post a Comment