Android Instrumented Unit Test Access Application Context

December 17, 2021
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun testContext() {
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        
        assertEquals("com.luasoftware.journey", appContext.packageName)
    }

    @Test
    fun testApplicationContext() {
        val context = ApplicationProvider.getApplicationContext<Context>()

        // ....
    }
}
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.