Instrumented Tests with Espresso and ActivityScenario
Let’s move on to instrumented tests. Begin by checking out the example that Android Studio created. In com.bignerdranch.android.geoquiz (androidTest), find and open ExampleInstrumentedTest.kt:
@RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.bignerdranch.android.geoquiz", appContext.packageName) } }
Much of this code is similar to the tests you have seen so far: You have a class containing a function annotated with @Test, and within that function there is an assertion to verify some behavior. But there are ...
Get Android Programming: The Big Nerd Ranch Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.