Android Unit Tests Requiring Context

后端 未结 8 1746
抹茶落季
抹茶落季 2020-12-13 23:47

I am writing my first Android database backend and I\'m struggling to unit test the creation of my database.

Currently the problem I am encountering is obtaining a va

8条回答
  •  离开以前
    2020-12-14 00:10

    You can use InstrumentationRegistry methods to get a Context:

    InstrumentationRegistry.getTargetContext() - provides the application Context of the target application.

    InstrumentationRegistry.getContext() - provides the Context of this Instrumentation’s package.


    For AndroidX use InstrumentationRegistry.getInstrumentation().getTargetContext() or InstrumentationRegistry.getInstrumentation().getContext().

提交回复
热议问题