I would guess that your test framework is catching all exceptions (junit does this), so the UncaughtExceptionHandler is never called.
However, if you run a test that starts a new Thread, the framework should not catch exceptions in that Thread. For example:
public void testUncaughtExceptionhandler()
{
Thread testThread = new Thread()
{
public void run()
{
throw new RuntimeException("Expected!");
}
};
testThread.start();
testThread.join();
}
That should successfully throw an exception that would be caught by the UncaughtExceptionHandler.
What this is testing is whether the UncaughtExceptionHandler is called at the right time. To test whether the handler responds correctly, you can simply call:
_unCaughtExceptionHandler.uncaughtException(thread, ex);
handing it a Thread and a Throwable. This will test whether the handler will behave correctly when it does run.\
These two tests verify whether the code that sets the default handler is correct and whether the handler itself is correct. These are different issues, and it is useful to test both.
It occurs to me that junit may rely on using its own UncaughtExceptionHandler, so when you override that, you break the framework. If that is the case, you might need to build and run the test without using junit.