Mobile Testing Strategies, Mocking & Automation: 15 Core Questions
Writing high-quality mobile tests ensures long-term stability. Modern mobile QA requires testing pixel-perfect interfaces using golden screenshots, mocking database and API layers, and automating end-to-end flows in cloud devices. This guide reviews 15 core mobile testing questions.
Questions Quick Links
- Q1. Mobile Testing Pyramid
- Q2. Network Mocking in Unit Tests
- Q3. Golden / Screenshot Layout testing
- Q4. Mocking Dependency injection graphs
- Q5. Appium vs. Maestro E2E tools
- Q6. Testing Asynchronous operations
- Q7. Resolving UI Test Flakiness
- Q8. Page Object Model (POM) in UI automation
- Q9. LCOV Code Coverage metrics in CI
- Q10. Testing ViewModels & BLoC state managers
- Q11. Cloud Test Lab configurations
- Q12. Local database in-memory testing
- Q13. Simulating physical sensors inputs
- Q14. Mutation Testing parameters
- Q15. Testing push notifications routing
Q1. Explain the Mobile Testing Pyramid. What are the ratios?
Answer:
The mobile testing pyramid structures test distribution:
- Unit Tests (70%): Test isolated methods, utility classes, and state management rules (fast and cheap).
- Integration Tests (20%): Test interactions between classes, widgets, and databases.
- E2E UI Tests (10%): Test full user flows directly on simulators or devices (slow and expensive).
Q2. How do you implement network mocking in unit tests?
Answer:
Avoid hitting live endpoints, which fail during network drops. Intercept and mock HTTP clients using mock objects (e.g. `mockito`, `mockk` in Kotlin, `MockTail` in Dart) or spin up local mock servers (like OkHttp's `MockWebServer`) to return hardcoded JSON payloads.
Q3. What are Golden Tests (Screenshot Testing)?
Answer:
Golden tests render layout views in memory and save them as master reference PNG files. During CI run executions, the test engine renders layout screens and compares pixels against the references, identifying visual regressions instantly.
Q4. How do you mock dependency injection configurations during testing?
Answer:
Configure your testing modules to override production inject factories. In Hilt, use `@UninstallModules` to disable production dependencies and inject fake mock components using test bindings.
Q5. Compare Appium vs. Maestro for E2E UI automation.
Answer:
- Appium: Multi-language framework utilizing WebDrivers. Highly flexible, but has slower execution speeds and complex configuration setups.
- Maestro: Modern mobile-focused automation tool using declarative YAML configuration files. Faster, less flakey, and handles system dialogs and network latency out-of-the-box.
Q6. How do you test asynchronous code without adding hardcoded sleep pauses?
Answer:
Hardcoded delays make tests slow and flakey. Use Coroutine/Dart test dispatchers (e.g. `runTest` in Kotlin, `test` in Dart) which swap timing behaviors with virtual time, allowing async timers to execute instantly.
Q7. What causes UI test flakiness? How do you resolve it?
Answer:
Flakiness is caused by network delays, slow disk operations, or rendering animations. Resolve this by:
- Mocking network calls to guarantee instant responses.
- Disabling system animations on testing simulators.
- Using **Idling Resources** to tell the test runner to pause until async operations finish.
Q8. What is the Page Object Model (POM) pattern in UI testing?
Answer:
POM abstracts UI elements and interactions into separate classes representing page layouts. Instead of writing raw element queries in every test script, tests call page object methods (e.g. `loginPage.enterCredentials()`), keeping scripts maintainable when layouts update.
Q9. How do you manage Code Coverage thresholds in CI pipelines?
Answer:
Generate LCOV coverage files during local test executions. In your GitHub Actions or GitLab CI configuration files, parse the report and check the percentage, failing builds if coverage falls below target levels (e.g., 80%).
Q10. How do you write unit tests for ViewModels or BLoC state managers?
Answer:
Instantiate the class under test with mocked dependencies. Assert initial states, dispatch event actions, and verify that the output state streams emit the correct values in sequence.
Q11. Explain how to run tests in cloud environments (Firebase Test Lab).
Answer:
Compile your application test APKs and upload them to Firebase Test Lab using CLI commands. The service deploys and executes tests across multiple real hardware models concurrently, returning logs and record videos.
Q12. Why should database unit tests use in-memory configurations?
Answer:
Writing test data to real files on disk makes tests slow and corrupts persistent files. Build databases using in-memory databases: `Room.inMemoryDatabaseBuilder(...)`. Memory drops when the test class destroys, guaranteeing clean state runs.
Q13. How do you simulate GPS locations during UI automation?
Answer:
Inject mocked coordinate payloads. On Android, use the location manager's mock provider interface. In iOS UI tests, set coordinates using simulator location override parameters.
Q14. What is Mutation Testing?
Answer:
Mutation testing validates test quality. It makes subtle changes to application source code (e.g. changing `>` to `<`) and runs unit tests. If your tests fail, the mutation is "killed" (success); if tests pass, the mutation "survived", highlighting gaps in your test assertions.
Q15. How do you test push notification handling programmatically?
Answer:
In E2E testing tools like Maestro, trigger mock notification payloads via terminal commands: `maestro push-notification --payload ...`. Assert that the app launches and displays the correct routed layout view.