AAD Quality Assurance & Compliance 2 — Questions and Answers
Question 1: Which Espresso method is used to check that a View is displayed on screen?
- matches(isDisplayed()) (Correct answer)
- check(isVisible())
- onView().assert(isShown())
- verify(displayed())
Correct answer: matches(isDisplayed())
Espresso uses `onView(matcher).check(matches(isDisplayed()))` to assert a View is visible.
Question 2: What does the `@SmallTest` annotation signal about an Android unit test?
- The test runs quickly and has no external dependencies (Correct answer)
- The test covers a small code file only
- The test uses fewer than 5 assertions
- The test is skipped on CI builds
Correct answer: The test runs quickly and has no external dependencies
`@SmallTest` indicates the test is fast and does not rely on the file system, network, or database.
Question 3: Which tool in Android Studio helps detect memory leaks by tracking object allocations over time?
- Memory Profiler (Correct answer)
- Network Inspector
- Layout Inspector
- CPU Profiler
Correct answer: Memory Profiler
The Memory Profiler records heap snapshots and allocation traces to identify leaked objects.
Question 4: When running instrumented tests on an emulator with `testInstrumentationRunner`, which class is the standard runner for AndroidX Test?
- androidx.test.runner.AndroidJUnitRunner (Correct answer)
- android.test.InstrumentationTestRunner
- org.junit.runners.JUnit4
- androidx.test.ext.junit.runners.AndroidJUnit4
Correct answer: androidx.test.runner.AndroidJUnitRunner
`androidx.test.runner.AndroidJUnitRunner` is declared in `build.gradle` as the instrumentation runner for AndroidX tests.
Question 5: What is the primary purpose of the `IdlingResource` API in Espresso?
- Synchronize test execution with asynchronous app operations (Correct answer)
- Pause the test for a fixed number of milliseconds
- Disable animations during UI tests
- Mock network responses in tests
Correct answer: Synchronize test execution with asynchronous app operations
`IdlingResource` tells Espresso when the app is idle so the framework waits before proceeding with assertions.
Question 6: Which Gradle command runs only unit tests (not instrumented tests) for the debug build variant?
- ./gradlew testDebugUnitTest (Correct answer)
- ./gradlew connectedDebugAndroidTest
- ./gradlew test --debug
- ./gradlew unitTestDebug
Correct answer: ./gradlew testDebugUnitTest
`testDebugUnitTest` executes local JVM unit tests for the debug variant without requiring a device.
Question 7: In Android's StrictMode, which policy detects disk reads on the main thread?
- ThreadPolicy (Correct answer)
- VmPolicy
- NetworkPolicy
- DiskPolicy
Correct answer: ThreadPolicy
`StrictMode.ThreadPolicy` monitors main-thread violations including disk reads and writes.
Which Espresso method is used to check that a View is displayed on screen?