mercredi 27 juin 2018

Can I ignore 'Instrumentation run failed due to 'Process crashed.' - so Test Runner will continue

When I run my test (to launch a video stream, and then let it run for 10 seconds), everything works (the stream runs, and I can even confirm views exist, etc), but the "Test Runner" crashes when my @Test is finished (after everything else has completed).

I get an error:

Test running failed: Instrumentation run failed due to 'Process crashed.'

But at this point in my test, I don't actually care about this, and would like to just ignore this.

Is there a way to just ignore this exit crash?

In my current situation, the test runner will exit the process, and not repeat, or run any other tests.

This is my test class:

@RunWith(AndroidJUnit4.class)
public class PlayerActivityTest extends InstrumentationTestCase {

    private LiveTvApplication app = (LiveTvApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();

    @Rule
    public ActivityTestRule<PlayerActivity> mActivityTestRule =
            new ActivityTestRule<>(PlayerActivity.class, true, true);

    @Rule
    public DaggerMockRule<LiveTvApplicationComponent> tvRepositoryRule = new DaggerMockRule<>(LiveTvApplicationComponent.class, new LiveTvModule(app))
            .set(new DaggerMockRule.ComponentSetter<LiveTvApplicationComponent>() {
                @Override
                public void setComponent(LiveTvApplicationComponent component) {
                    LiveTvApplication app = (LiveTvApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
                    app.setComponent(component);
                }
            });

    @Mock
    TvStreamDataRepository tvStreamDataRepository;

    /**
     * Launch Live TV Stream
     */
    @Test
    public void launchTV() {
        Context targetContext = InstrumentationRegistry.getInstrumentation()
                .getTargetContext();

        String argsKey = "value123";
        when(tvStreamDataRepository.getStreamArgs(argsKey)).thenReturn(tvStreamArgs);


       Intent mpdIntent = new Intent(targetContext, PlayerActivity.class)
            .putExtra(BundleKeys.APP_CONFIG, Parcels.wrap(appConfig))
            .putExtra(BundleKeys.STREAM_ARGS_KEY, argsKey);

            mActivityTestRule.launchActivity(mpdIntent);

            try {
                Thread.sleep(WAIT_TIME);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

// I CAN ALWAYS GET HERE - After this I don't care
// But the Test Runner will exit with the "Process Crashed" error
// and not run any other test

    }


}

Aucun commentaire:

Enregistrer un commentaire