Example custom test runner crashes
See original GitHub issueThe 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:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No,
ApplicationProvider.getApplicationContext()
just redirects to theInstrumentationRegistry
, this won’t help. I’m suggesting to use the created application context of the runner itself, sinceAndroidJUnitRunner
extends fromInstrumentation
.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)