Get context of test project in Android junit test , not InstrumentedTest

17 Views Asked by At

I need to use Jacoco, but I need to get context. When I use this command I got this error:

No instrumentation registered! Must run under a registering instrumentation.

Is there a way to use jacoco in InstrumentedTest?

public class ExampleUnitTest {
    @Test
    public void addition_isCorrect() {
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        assertEquals("com.example.jacoco", appContext.getPackageName());
    }
}
0

There are 0 best solutions below