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

前端 未结 6 922
太阳男子
太阳男子 2020-12-08 09:42

I have an Activity that pulls an object from an Application extended class (application context) from within the OnCreate() method.

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 10:28

    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();
    

提交回复
热议问题