-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Robolectric 4.6.1 does not work with ActivityScenario from androidx.test.monitor 1.3.0 #6781
Comments
Is your gradle file forcing a androidx.test:monitor:1.3.0 version? org.robolectric:robolectric:4.61 has a dependency on androidx.test:monitor:1.4.0 +. IMO its working as expected that it isn't backwards compatible with older monitor versions. |
@brettchabot unfortunately so. The project uses LeakCanary which works with some |
This sounds like a LeakCanary bug then |
Of course, there is an issue reported to LeakCanary and it will eventually be fixed. Anyway, third-party projects and the question of whether Robolectric should be compatible to older versions of |
As a temporary workaround, I was able to configure the registry manually: fun installHack() {
val instrumentation = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation()
val arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments()
androidx.test.InstrumentationRegistry.registerInstance(instrumentation, arguments)
}
class MyTest {
init {
installHack()
}
...
} |
Hi @nborodikhin , the PR that migrated registry API for |
Description
Hello,
I am using
ActivityScenario
as outlined in the AndroidX test guide. After upgrading Robolectric to 4.6.1 I got two issues - one reported as #6593 and the other one:The root cause of this issue is that
LocalActivityInvoker
is getting target context from now-deprecatedInstrumentationRegistry
here but in this particular combination of frameworks it is never set.The change that broke compatibility it the reimplementation
RoboMonitoringInstrumentation
: daa9d1aWhy combination Robolectric 4.5 +
androidx.test
1.3 worksandroidx.test
has two independentInstrumentationRegistry
classes:androidx.test.InstrumentationRegistry
andandroidx.test.platform.app.InstrumentationRegistry
RoboMonitoringInstrumentation
descends fromandroidx.test.runner.MonitoringInstrumentation
androidx.test.runner.MonitoringInstrumentation
configures both instrumentation registries: linkLocalActivityInvoker
accesses deprecated instrumentation registry which is explicitly set upWhy combination Robolectric 4.6 +
androidx.test
1.4 worksandroidx.test
has has one mainInstrumentationRegistry
implementation:androidx.test.platform.app.InstrumentationRegistry
androidx.test.InstrumentationRegistry
forwards all calls to the main one: linkRoboMonitoringInstrumentation
which installs itself into only one instrumentation registry: linkLocalActivityInvoker
accesses configured instrumentation registry via the forwarding provided by the deprecated oneWhy combination Robolectric 4.5 +
androidx.test
1.3 does not workandroidx.test
has two independentInstrumentationRegistry
classes:androidx.test.InstrumentationRegistry
andandroidx.test.platform.app.InstrumentationRegistry
RoboMonitoringInstrumentation
which installs itself into one registry: linkLocalActivityInvoker
is trying to get target context from now-deprecatedInstrumentationRegistry
which is not configuredSteps to Reproduce
Robolectric & Android Version
Robolectric: 4.6.1
androidx.test
: 1.3.0Link to a public git repo demonstrating the problem:
Proposed solution
Robolectric does not use deprecated
InstrumentationRegistry
with the exception ofLocalActivityInvoker
. I think the appropriate solution would be to migrate deprecated registry access inLocalActivityInvoker
to use main registryandroidx.test.platform.app.InstrumentationRegistry
.The text was updated successfully, but these errors were encountered: