AndroidX : No instrumentation registered! Must run under a registering instrumentation

Update

You should no longer encounter this error if youre using the latest gradle version.


I also encountered this issue.

If you look at migrating to Robolectric 4.0 here, it suggest to add the following line in your gradle.properties.

android.enableUnitTestBinaryResources=true

The problem is that, if you add this you your gradle.properties, it will output this warning:

WARNING: The option setting
‘android.enableUnitTestBinaryResources=true’ is experimental and
unsupported.

Now, if you look at Robolectric releases here. You could see that this is a known issue where they state that

Android Gradle Plugin may report the following warning, which may be safely ignored: WARNING: The option setting ‘android.enableUnitTestBinaryResources=true’ is experimental and unsupported.. Android Gradle Plugin 3.4 will resolve this issue.

I believe unless you could update you gradle to 3.4. You won’t be able to solve this issue.

What I did instead was to include Robolectric 4.0 as dependency.

testImplementation "org.robolectric:robolectric:4.0.2"

and annotate my test class with

@RunWith(RobolectricTestRunner::class)

This should make your test work.

Now when you run the test, you’ll notice that Robolectric will log the following:

[Robolectric] NOTICE: legacy resources mode is deprecated; see
http://robolectric.org/migrating/#migrating-to-40

Ignore this for now but as soon as you could update your gradle, migrate to the new Robolectric testing.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)