Testing
242 bites tagged Testing — interview questions with model answers, and 60-second explainers.
Integration Testing: Do Your Components Play Well Together?
Integration testing verifies that different software modules, like an API and a database, work correctly together. It's used to catch bugs in the interactions between components, such as data format mismatches. The footgun is writing slow, brittle tests.
Unit Testing: Verifying Code's Smallest Parts
Think of unit tests as checking each Lego brick for defects before building the castle. They confirm your smallest code pieces, like a single function, behave correctly in isolation.
Build Matrix: Test All The Combinations
A build matrix automatically creates multiple jobs by combining different configurations. Use it to test your code across various operating systems, language versions, or dependencies without duplicating your workflow file.
Code Coverage: What Your Tests Don't Tell You
Code coverage measures which lines of code your tests execute, not how well they're tested. It's used in CI to enforce a testing baseline, but the footgun is mistaking high coverage for high quality—100% coverage can exist with zero useful assertions.
Automated Testing: Catch Bugs Before They Ship
Automated testing is like a robot QA engineer checking every code change instantly. It's the engine of CI/CD pipelines, running tests on every commit to give developers immediate feedback on business risks.
Google Play Release Tracks: A Funnel for Quality
Google Play's release tracks are a funnel for quality, moving from a small trusted group to the public. Use them to get feedback, from internal QA (Internal track) to a wider audience (Closed/Open tracks), before a full production launch.
Isolating Units for Tests with Mockito-Kotlin
Mockito-Kotlin creates fake objects (mocks) to stand in for real dependencies in your tests. This lets you test a class in isolation, for example, testing a ViewModel without making a real network call. The footgun is testing implementation, not behavior.
UI Automator: Black-Box UI Testing for Android
Think of UI Automator as a robot that tests your app by looking at the screen, not your code. It's for end-to-end tests that cross app boundaries, like interacting with the system Settings. The footgun: tests are powerful but can be slow and brittle.
Testing Coroutines: Control Time with `runTest`
Test asynchronous coroutine code as if it were synchronous. The `kotlinx-coroutines-test` library lets you control a virtual clock. Use `runTest` to wrap tests calling suspend functions, ensuring your test waits for async work before asserting results.
Espresso for Android UI Testing
Espresso is an Android framework for automated UI tests. As an instrumented test, it runs on a device or emulator to simulate user interactions, helping you verify app behavior and UI correctness as part of a complete testing strategy.
Robolectric: Run Android Unit Tests on the JVM
Robolectric runs Android unit tests on a regular JVM, not a slow emulator. Use it in CI/TDD to test logic like Activity lifecycles without the minutes-long build-deploy cycle. The footgun is over-mocking; Robolectric tests behavior, not just implementation.
ActivityScenario: Test Your Android Activities in Isolation
ActivityScenario lets you launch and control an Android Activity's lifecycle within an instrumented test. Use it to verify UI behavior during events like screen rotation or process death, isolating the component for reliable testing.
AndroidX Test: The Standard Android Testing Toolkit
AndroidX Test offers a unified API for all Android testing, from local unit tests to on-device UI automation. It's the standard for building robust, testable apps. The footgun: accidentally bundling test-only dependencies into your production APK.
Instrumentation Tests: Testing on a Real Android Device
Instrumentation tests are like test-driving your app on a real device or emulator. They verify code that depends on the Android framework, like UI interactions or sensor access.
Truth: Fluent Assertions for Clearer Tests
Truth makes tests read like English: `assertThat(actual).is...`. It provides clearer assertions than standard JUnit, with far more helpful failure messages, especially for collections. The main footgun is a potential Guava dependency conflict.
JUnit on Android: Fast, Local Unit Tests
JUnit on Android runs tests directly on your local machine's JVM, not a device, making them extremely fast. Use it for business logic and ViewModels that don't touch Android APIs. The footgun is trying to access framework code like `Context`, which will fail.
The Testing Pyramid: Fast Feedback, Low Cost
The Testing Pyramid guides test suite structure: a wide base of fast unit tests, a smaller middle of integration tests, and a tiny top of slow UI tests. This model is key for Android's local, instrumented, and UI tests. The footgun is inverting it.
Testing with Hilt: Swapping Dependencies for Isolation
Hilt testing swaps real app components for fakes, isolating your code under test without manual setup. It's used in UI and unit tests to replace production dependencies like network clients with test doubles.
Testing Room Databases: On-Device vs. Local JVM
Test your Room database in two ways: on an Android device for realism, or on your local JVM for speed. This is crucial for verifying DAO queries and preventing data bugs. The footgun is assuming local tests behave identically to on-device tests.
Compose UI Testing: Find Nodes, Assert State, Perform Actions
Compose UI tests treat your UI as a node tree. You find nodes by properties (like text or a test tag), assert their state (e.g., 'is displayed'), and perform actions like clicks. Use it to verify composables react correctly to state changes or user input.
Behavior-Driven Development (BDD): Requirements as Tests
BDD turns requirements into executable tests using a shared, human-readable language. Use it for complex features where business and tech teams need to align. The footgun is writing BDD scenarios *after* coding, missing the collaborative design benefit.
ATDD: Aligning Code with Business Needs Before You Build
Acceptance Test-Driven Development (ATDD) is a communication framework where business, developers, and testers write acceptance tests together *before* coding begins. This ensures everyone understands the requirements.
Contract Testing: Test Interfaces, Not Integrations
Contract testing ensures services work together without slow integration tests. It's a formal agreement where a 'consumer' defines its needs, and a 'provider' proves it can meet them.
The Test Pyramid: Fast Feedback, Stable Code
The Test Pyramid is a strategy for balancing automated tests: write many fast unit tests, fewer integration tests, and very few slow end-to-end tests. It guides CI/CD pipelines to catch failures quickly. The footgun is over-relying on slow E2E tests.
Get Testing bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.