@@ -426,6 +426,21 @@ InstrumentationResultPrinter getInstrumentationResultPrinter() {
426
426
return instrumentationResultPrinter ;
427
427
}
428
428
429
+ private void invokeRemoteMethod () {
430
+ try {
431
+ new ReflectiveMethod <Void >(
432
+ runnerArgs .remoteMethod .testClassName , runnerArgs .remoteMethod .methodName )
433
+ .invokeStatic ();
434
+ } catch (ReflectionException e ) {
435
+ Log .e (
436
+ LOG_TAG ,
437
+ String .format (
438
+ "Reflective call to remote method %s#%s failed" ,
439
+ runnerArgs .remoteMethod .testClassName , runnerArgs .remoteMethod .methodName ),
440
+ e );
441
+ }
442
+ }
443
+
429
444
@ Override
430
445
public void onStart () {
431
446
Log .d (LOG_TAG , "onStart is called." );
@@ -434,21 +449,11 @@ public void onStart() {
434
449
try {
435
450
setJsBridgeClassName ("androidx.test.espresso.web.bridge.JavaScriptBridge" );
436
451
super .onStart ();
452
+
437
453
Request testRequest = buildRequest (runnerArgs , getArguments ());
438
454
439
455
if (runnerArgs .remoteMethod != null ) {
440
- try {
441
- new ReflectiveMethod <Void >(
442
- runnerArgs .remoteMethod .testClassName , runnerArgs .remoteMethod .methodName )
443
- .invokeStatic ();
444
- } catch (ReflectionException e ) {
445
- Log .e (
446
- LOG_TAG ,
447
- String .format (
448
- "Reflective call to remote method %s#%s failed" ,
449
- runnerArgs .remoteMethod .testClassName , runnerArgs .remoteMethod .methodName ),
450
- e );
451
- }
456
+ invokeRemoteMethod ();
452
457
}
453
458
454
459
// TODO(b/162075422): using deprecated isPrimaryInstrProcess(argsProcessName) method
@@ -457,16 +462,13 @@ public void onStart() {
457
462
return ;
458
463
}
459
464
460
- try {
461
- TestExecutor .Builder executorBuilder = new TestExecutor .Builder (this );
462
- addListeners (runnerArgs , executorBuilder );
463
- results = executorBuilder .build ().execute (testRequest );
464
- } catch (Throwable t ) {
465
- final String msg = "Fatal exception when running tests" ;
466
- Log .e (LOG_TAG , msg , t );
467
- onException (this , t );
468
- }
469
-
465
+ TestExecutor .Builder executorBuilder = new TestExecutor .Builder (this );
466
+ addListeners (runnerArgs , executorBuilder );
467
+ results = executorBuilder .build ().execute (testRequest );
468
+ } catch (Throwable t ) {
469
+ final String msg = "Fatal exception when running tests" ;
470
+ Log .e (LOG_TAG , msg , t );
471
+ onException (this , t );
470
472
} finally {
471
473
Trace .endSection ();
472
474
}
@@ -623,6 +625,13 @@ public boolean onException(Object obj, Throwable e) {
623
625
final StrictMode .ThreadPolicy oldPolicy = StrictMode .allowThreadDiskWrites ();
624
626
try {
625
627
instResultPrinter .reportProcessCrash (e );
628
+ } catch (Throwable t ) {
629
+ // It is possible for the test infrastructure to get sufficiently messed up that even this
630
+ // can fail (with a NoSuchMethodError from Failure.getTrace()!). Don't let that get in the
631
+ // way of sending events reporting the problems, since that can make the difference between
632
+ // "test failed with a useful error message" and "test mysteriously timed out and the
633
+ // developer has to go spelunking in the system logcat".
634
+ Log .e (LOG_TAG , "Failed to report process crash." , t );
626
635
} finally {
627
636
StrictMode .setThreadPolicy (oldPolicy );
628
637
}
0 commit comments