How can we access context of an application in Robolectric?

后端 未结 14 1533
既然无缘
既然无缘 2020-12-05 03:32

Actually, I need to get a response of an API call, for that I required Context.

14条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 04:13

    For the latest Robolectric 4.3 as of right now in 2019 `

    ShadowApplication.getInstance()

    ` and

    Roboletric.application

    are both depricated. So I am using

    Context context = RuntimeEnvironment.systemContext;
    

    to get Context.

提交回复
热议问题