I'm using an ExecutorService to run tests upon a system. The problem arises when a test fails for some reason. These reason can be a many, and of course I'm logging these errors.
But I would like to, in real-time, notify the user of an error. So when an error occurs, the longer it reaches the top, it becomes a TestFailedException
with a message and a cause. I would like to catch this exception and notify the user, but I can't seem to do that.
This is an example of a method that is actually starting the thread that runs the test:
public void asyncRunTestfixture(Concretetest concretetest) {
ExecutorService executor = Executors.newCachedThreadPool();
FutureTask<Boolean> futureTask_1 = new FutureTask<Boolean>(new Callable<Boolean>() {
@Override
public Boolean call() throws TestFailedException {
return RunTestInFixture(concretetest);
}
});
executor.execute(futureTask_1);
executor.shutdown();
}
But even though call throws an exception, I can't catch it elsewhere, neither now or if I say the asyncRunTestfixture methods throws an exception.
How can I solve this?