Testing
242 bites tagged Testing — interview questions with model answers, and 60-second explainers.
How do you widget-test states without real network calls?
This tests UI isolation from I/O. Mock the repository with Mockito, stub methods to yield loading, success, and error, and inject it via constructor or provider. Avoid real HTTP calls or unmocked clients in widget tests.
Unit, widget, and integration test differences in Flutter
Tests your grasp of Flutter's test pyramid and isolation levels. Unit tests check pure Dart logic; widget tests verify UI in a headless environment; integration tests exercise the full app on a device. Red flag: saying widget tests require an emulator.
Legacy Integration Testing with flutter_driver
flutter_driver remotely pilots your app from a host via Dart VM service, common in legacy codebases with host-side scripts. Do not treat it as an in-process widget test because it runs outside the app; you cannot inspect state or use flutter_test matchers.
Cross-Browser Testing Automation
Rendering engines disagree, so your CSS may break in Safari while Chrome looks fine. Automation runs your UI across real browsers in CI to catch visual drift early. The footgun is testing every pixel, which breeds brittle suites that teams eventually ignore.
How would you enforce WCAG 2.1 AA compliance across CI/CD?
Layer axe-core in unit tests, Playwright Axe in CI, visual regression for focus states, and gate deploys on severity. Layered a11y automation across build and deploy. One post-build audit, not distributed checks.
Design an automated system to validate tutorial snippets against new releases
Separate API docs from other snippets; run CI on new dependency versions; inject secrets via hooks. Auto-validating docs when libraries release updates. Manual checks or credentials in markdown.
How would you diagnose, report, and mitigate E2E flakiness at scale?
Tests metric-driven pipeline hygiene versus retry band-aids. Strong answers baseline flakiness rates, identify offenders via CI history, quarantine chronic flakes from presubmit, and fix root causes like concurrency.
How would you block merges when PR coverage drops 2%?
Upload coverage to Codecov, set a project status threshold of 2, and require the check in branch protection. Your ability to wire automated coverage gates into CI and version control.
Difference between unit and integration tests and CI pipeline placement
Unit tests isolate code and run fast in the build stage; integration tests verify real wiring later. Target 70 percent unit tests. Grasp of the testing pyramid and CI gating. Claiming both run together or cost the same.
What is Android Test Orchestrator and how does it isolate tests?
Tests process-level isolation in Android UI suites. A strong answer says it runs each test in its own Instrumentation process, stopping crashes or leaked state from cascading, and notes slower startup.
What is the role of TestDispatcher and runTest in coroutine testing?
This tests coroutine test infrastructure and virtual time control. A great answer says runTest installs a TestDispatcher and TestScope, skips delays automatically, and exposes advanceTimeBy to test timeouts instantly.
How would you implement and register a custom IdlingResource?
Implement the three IdlingResource methods with an atomic counter; register via IdlingRegistry in setup and unregister in teardown. Whether you know Espresso's async contract. Suggesting Thread.sleep or polling loops.
How do you test a Compose click and verify state change?
This tests Compose semantics and interaction-to-assertion flow. Mention ComposeTestRule, onNodeWithTag, performClick, and assert on the changed node with assertIsDisplayed or assertTextEquals.
Mock vs Fake test doubles: when to use a Fake Repository?
Tests if you know a Fake is a working lightweight implementation while a Mock verifies interactions. Good answers define Fake as in-memory with real logic, Mock as expectation-based, and choose a Repository Fake when many tests need reusable state.
Explain integration tests and isolate Room DAO tests
Tests integration vs unit testing and Room isolation. Outline: verify real DAO-to-DB interaction with Room.inMemoryDatabaseBuilder; reset state by closing and recreating the DB in @After. Red flag: mocking the DAO or using an on-disk database.
What is the difference between test and androidTest source sets?
Say test runs on the JVM for unit tests mocking Android classes, while androidTest runs on device for instrumented tests. This tests understanding of test environments. Saying both need a device or treating them interchangeably.
Replace a production NetworkService with a fake in Hilt instrumented tests
Tests whether you know Hilt test overrides beyond basic DI. A strong answer covers @BindValue for field-level fakes and @TestInstallIn or @UninstallModules for module swaps.
Propose a multi-sprint strategy to fix an inverted test pyramid
Audit E2E for redundancy; scaffold unit/integration tests; migrate per sprint, keep critical E2E; gate on fast feedback. Refactoring under delivery pressure. Big-bang rewrites or deleting all E2E without a safety net.
Explain the Test Pyramid and how it guides testing strategy
Favor fast unit tests, a middle service layer, and few UI tests as second defense. Your grasp of test cost, speed, and brittleness by layer. Treating it as a fixed ratio or saying all end-to-end tests need a.
Describe the Red-Green-Refactor cycle in TDD. What is each step's purpose?
This checks if you understand TDD as a design discipline, not just testing. A strong answer maps Red to a failing test defining the interface, Green to minimal passing code, and Refactor to cleaning both codebases without changing behavior.
How do you fix an inverted test pyramid?
This tests your ability to create a pragmatic, multi-sprint plan to improve test suite health. A good answer involves analyzing tests, getting buy-in, then incrementally adding unit/integration tests while refactoring old E2E tests.
How would you introduce TDD to a team?
Tests your ability to drive change pragmatically. A great answer outlines a gradual adoption: start with a pilot, gather data on bug rates and velocity, and scale based on demonstrated value. A red flag is demanding immediate, universal adoption.
Explain the Test Pyramid and how it guides your strategy.
Tests your grasp of balanced automated testing. Define the pyramid's layers (Unit, Service, UI), explain trade-offs like speed and cost, then apply it to a new service. A red flag is describing the layers without explaining the 'why' behind the shape.
Describe the Red-Green-Refactor cycle in Test-Driven Development
This tests your grasp of TDD's core loop and its design benefits. Outline the cycle: Red (failing test), Green (minimal code to pass), and Refactor (clean up). Mention creating a test list first. A red flag is ignoring the critical Refactor step.
Get Testing bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.