mercredi 23 octobre 2019

Can ApplicationProvider.getApplicationContext be safely used in a Robolectric unit test?

Is it possible to call androidx.test.core.app.ApplicationProvider.getApplicationContext within a Robolectric unit test i.e. located in the Android project test directory?

When I attempt this, I get the error java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.

As a result, I'm wondering if this call can only be made in instrumentation tests i.e. tests located in the Android project androidTest directory. If that's not the cause, what else might be responsible?

Aucun commentaire:

Enregistrer un commentaire