What's the difference between getTargetContext() and getContext (on InstrumentationRegistry)?

前端 未结 3 960
傲寒
傲寒 2020-12-14 00:42

I\'m using the new Android Testing Support Library (com.android.support.test:runner:0.2) to run Instrumentation Tests (a.k.a Device or Emulator Tests).

3条回答
  •  佛祖请我去吃肉
    2020-12-14 01:33

    You may need InstrumentationRegistry.getContext() for access to raw resources of a test case.

    E.g., to access app/src/androidTest/res/raw/resource_name.json in a TestCase:

    final Context context = InstrumentationRegistry.getContext(); InputStream is = context.getResources().openRawResource(com.example.package.test.R.raw.resource_name);

提交回复
热议问题