You can use InstrumentationRegistry.getInstrumentation().getTargetContext() in the most cases from androidx.test.platform.app.InstrumentationRegistry.
If you need the Application, you can use ApplicationProvider.getApplicationContext<MyAppClass>().
If you haven’t already, I think you can also use the new test dependency:
androidTestImplementation 'androidx.test:core:1.0.0-beta02'.