Complete the code to annotate an instrumented test class.
import androidx.test.ext.junit.runners.AndroidJUnit4 @[1] class ExampleInstrumentedTest { }
The @RunWith(AndroidJUnit4::class) annotation tells the test runner to use the AndroidJUnit4 class for instrumented tests.
Complete the code to mark a function as an instrumented test.
import org.junit.Test class ExampleInstrumentedTest { @[1] fun useAppContext() { // test code here } }
The @Test annotation marks a function as a test method to be run by the test runner.
Fix the error in the code to get the app context in an instrumented test.
import androidx.test.platform.app.InstrumentationRegistry val appContext = InstrumentationRegistry.[1].targetContext
The getInstrumentation() method returns the Instrumentation instance, from which you can get the target context.
Fill both blanks to launch an activity in an instrumented test.
import androidx.test.core.app.ActivityScenario val scenario = ActivityScenario.[1](MainActivity::class.[2])
ActivityScenario.launch() starts the activity for testing. The java property gets the Java class reference.
Fill all three blanks to assert the app package name in an instrumented test.
import androidx.test.platform.app.InstrumentationRegistry import org.junit.Assert.* val appContext = InstrumentationRegistry.[1].targetContext assertEquals("[2]", appContext.[3].packageName)
Use getInstrumentation() to get the Instrumentation, then get the applicationContext from the target context to check the package name.