question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example custom test runner crashes

See original GitHub issue

The README.md states to do:

public class ExampleTestRunner extends AndroidJUnitRunner {
  @Override
  public void onStart() {
      TestButler.setup(ApplicationProvider.getApplicationContext());
      super.onStart();
  }

  @Override
  public void finish(int resultCode, Bundle results) {
      TestButler.teardown(ApplicationProvider.getApplicationContext());
      super.finish(resultCode, results);
  }
}

however, this crashed for me with androidX’s test-core v1.0.0 with this:

java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.
   at androidx.test.platform.app.InstrumentationRegistry.getInstrumentation(InstrumentationRegistry.java:45)
   at androidx.test.core.app.ApplicationProvider.getApplicationContext(ApplicationProvider.java:41)
   at my.custom.AndroidJUnitRunner.onStart(AndroidJUnitRunner.kt:11)
   at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)

so I figured this might be a race here that the registry doesn’t know of the instrumentation yet. It is however totally unneccessary to use the registry at all, since the runner itself is the instrumentation that we need, so it is sufficient to do this:

public class ExampleTestRunner extends AndroidJUnitRunner {
  @Override
  public void onStart() {
      TestButler.setup(getTargetContext());
      super.onStart();
  }

  @Override
  public void finish(int resultCode, Bundle results) {
      TestButler.teardown(getTargetContext());
      super.finish(resultCode, results);
  }
}

This properly initialized TestButler for me, i.e. disabled animations, and ran my tests.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
realdadfishcommented, Dec 4, 2018

No, ApplicationProvider.getApplicationContext() just redirects to the InstrumentationRegistry, this won’t help. I’m suggesting to use the created application context of the runner itself, since AndroidJUnitRunner extends from Instrumentation.

0reactions
mennatallahcommented, Jul 17, 2020

I have the same issue when I’m trying to Run my feature file as iam using a cucumber integrated with Espresso for Android UI java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation. at androidx.test.platform.app.InstrumentationRegistry.getInstrumentation(InstrumentationRegistry.java:45)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Instrumentation run failed due to 'Process crashed.'
I have a custom JUnitRunner and sometimes the test passes, on some occasions, it fails. Sometimes it crashes after test passes, sometimes all ......
Read more >
Need Examples on running with Dagger and Custom Test Class
If you replace the Application name in the android manifest for the tests, the Test runner will crash immediately and there is no...
Read more >
How to stress test a PC to find errors and crashes - YouTube
Tutorial : Learn how to stress test a new PC build and the software involved! Start configuring your next custom gaming PC with...
Read more >
AndroidJUnitRunner - Android Developers
The AndroidJUnitRunner class is a JUnit test runner that lets you run instrumented JUnit 4 tests on Android devices, including those using ...
Read more >
Diagnosing issues using crash reports and device logs
Use crash reports and device logs to debug app issues. ... Add tests with the XCTest framework to ensure the issue doesn't reoccur...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found