How can we access context of an application in Robolectric?

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

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

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 04:13

    First add the following to your build.gradle:

    testImplementation 'androidx.test:core:1.2.0'

    then use:

    ApplicationProvider.getApplicationContext() as Application

提交回复
热议问题