Adds a default uncaught exception handler for GTM tests so that the iOS test
framework can detect when a forked thread fails.
Change on 2017/02/24 by kstanger
@@ -137,6 +137,9 @@ public class JUnitTestRunner {
* @returns Zero if all tests pass, non-zero otherwise.
*/
public int run() {
+ if (outputFormat == OutputFormat.GTM_UNIT_TESTING) {
+ Thread.setDefaultUncaughtExceptionHandler(new GtmUncaughtExceptionHandler());
+ }
Set<Class<?>> classesSet = getTestClasses();
Class<?>[] classes = classesSet.toArray(new Class<?>[classesSet.size()]);
sortClasses(classes, sortOrder);
@@ -385,6 +388,16 @@ public class JUnitTestRunner {
e.printStackTrace(out);
}
+ private class GtmUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
+
+ @Override
+ public void uncaughtException(Thread t, Throwable e) {
+ out.print("Exception in thread \"" + t.getName() + "\" ");
+ e.printStackTrace(out);
+ out.println("** TEST FAILED **");
+ }
+ }
+
@WeakOuter
private class GtmUnitTestingTextListener extends RunListener {
