Accessing application context from TestSuite in Setup() before calling getActivity()

Ok, this issue is resolved. To get access to the context before getActivity() has been called you need to call this function:

Context context = this.getInstrumentation().getTargetContext().getApplicationContext();

With the newer UI testing framework getInstrumentation() is no longer available. One way to get hold of the Application object is to cast the application Context:

Application app = 
        (Application) InstrumentationRegistry
                .getTargetContext()
                .getApplicationContext();

You can get the application context using the androidx.test.core.app.ApplicationProvider.getApplicationContext(). Cast that to your application and it should be the right context.