Quality Assurance: Feature Testing Strategy and Test Reliability
BehavioralModel answerLast updated
Design a comprehensive testing approach for a new feature, then address how to maintain a reliable automated test suite by eliminating flaky tests.
You're responsible for ensuring quality on an engineering team. A new capability is about to begin the testing phase.
First, describe your complete testing strategy: how you approach verifying this capability from initial requirements through production release. Include how you create your test plan, what techniques you use to identify test scenarios, how you decide which tests to automate versus execute manually, and what criteria determine the feature is ready to ship.
Second, explain your approach to unreliable automated tests—those that sometimes pass and sometimes fail without any actual code changes. Cover how you identify these problematic tests, investigate their causes, resolve them, and prevent future occurrences.
For context, choose a specific example feature (such as a password reset flow, a payment processing API, or a search ranking algorithm) and reference it throughout your response.
Be concrete about processes, techniques, and decision-making criteria rather than speaking in generalities.
Hints
Hint 1
Think through the complete lifecycle from requirements review to production monitoring, not just writing test cases
Hint 2
Consider both the technical aspects (boundary values, race conditions) and the process aspects (who owns fixing flaky tests)
Hint 3
Strong answers balance thoroughness with pragmatism—you cannot test everything, so explain how you prioritize
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
I'll use a user authentication API endpoint (login with email/password) as my concrete example.
Part 1: Testing Strategy for New Features
Requirements Analysis Phase
Before any code exists, I review the specification with the product and engineering teams. For the login endpoint, I'd ask:
- What are the exact success/failure response codes and messages?
- What constitutes a valid email format and password policy?
- How many failed attempts trigger account lockout?
- What's the expected response time under normal and peak load?
- Are there audit logging requirements?
These questions surface ambiguities early and establish testability requirements like observable states and error messages.
Test Case Design
I use multiple systematic techniques to ensure coverage:
Equivalence Partitioning & Boundary Analysis:
- Valid credentials (happy path)
- Email boundaries: empty string, single character, maximum length, special characters
- Password boundaries: minimum/maximum length, allowed character sets
- Invalid format: malformed email, missing @ symbol
State Transition Testing:
- Account states: active → locked after N failures, locked → active after timeout
- Session states: unauthenticated → authenticated → expired
Negative Scenarios:
- Wrong password with correct email
- Correct password with nonexistent email
- SQL injection attempts in input fields
- Concurrent login attempts from different locations
- Requests with missing required headers
Error Handling:
- Database connectivity failure
- Downstream service timeout
- Rate limiting threshold exceeded
Test Level Assignment
I assign each scenario to the appropriate level based on feedback speed and isolation needs:
Unit tests (developer-owned, run on every commit):
- Password hashing logic
- Email validation regex
- Token generation functions
Integration tests (QA + dev collaboration, run in CI):
- API contract: request/response structure
- Database read/write operations
- Cache behavior
End-to-end tests (selective, run before release):
- Complete login flow including session creation
- Account lockout behavior across multiple requests
- Critical security scenarios
Manual exploratory testing:
- Usability with real-world email variations
- Browser autofill interactions
- Performance under degraded network conditions
I automate anything that's repetitive, deterministic, and fast. Exploratory testing targets the gaps automated checks miss—surprising interactions and edge cases we didn't anticipate.
Prioritization
I prioritize by risk = (likelihood of failure) × (impact of failure):
P0 - Critical: Valid credentials must succeed; security vulnerabilities must not exist P1 - High: Error messages must be clear; lockout must work correctly P2 - Medium: Performance under high load; all error codes covered P3 - Low: Exact wording of success messages; logging format details
Release Readiness Criteria
The feature is ready when:
- All P0 and P1 test cases pass
- Security review completed with no critical findings
- Performance benchmarks meet SLA (e.g., p95 latency < 200ms)
- Monitoring and alerting configured
- Documentation complete for API consumers
- Rollback plan validated
I also verify we have at least one production metric to measure success (e.g., login success rate, p99 latency).
Part 2: Managing Flaky Tests
Detection
I identify flaky tests through:
- Failure patterns in CI: Tests that fail, then pass on retry without code changes
- Metrics tracking: Test failure rate over time; tests with <100% and >0% pass rate
- Developer reports: "This test failed locally but passes in CI"
I confirm flakiness by re-running the suspected test 20-50 times in isolation. If it fails even once without code changes, it's flaky.
Root Cause Categories
Timing Issues (most common):
- Hard-coded sleeps that are too short
- Polling without proper wait conditions
- Race conditions between test setup and execution
Diagnosis: Add detailed logging around the failure point; check if failures correlate with system load.
Test Isolation Problems:
- Shared mutable state between tests
- Database records not cleaned up
- File system or cache pollution
Diagnosis: Run the test alone versus in the full suite; check if failure rate changes.
External Dependencies:
- Network requests to unreliable services
- Date/time dependent logic without mocking
- Random number generation without seeding
Diagnosis: Check if failures correlate with external service status; review code for non-deterministic inputs.
Infrastructure Issues:
- Resource contention in CI environment
- Flaky test infrastructure itself (Selenium grid, device farms)
Diagnosis: Compare failure rates across different CI runners; check for memory/CPU constraints.
Resolution Approach
For timing issues: Replace sleep(5) with proper wait conditions (waitUntil(elementVisible, timeout=10)). Use exponential backoff for retries of eventually-consistent operations.
For isolation issues: Ensure each test has independent setup/teardown. Use unique identifiers (UUIDs, timestamps) for test data. Run tests in random order to expose hidden dependencies.
For external dependencies: Mock external services in unit/integration tests. Use contract testing instead of live calls. For unavoidable external dependencies, implement retry logic with exponential backoff, but prefer replacing the flaky dependency.
Never: Simply increase timeout values without understanding why. Never add automatic retries to hide flakiness—that destroys signal.
Process and Prevention
Immediate quarantine: When a test is confirmed flaky, I quarantine it (move to a separate suite that doesn't block CI) and file a ticket with the failure pattern and initial diagnosis.
Ownership: The team that owns the code under test owns fixing the flaky test. QA provides diagnosis support but doesn't let developers defer this work.
Measurement: Track flake rate as a team metric (goal: <1% of test runs have any flake). Review quarantined tests weekly; if not fixed in 2 weeks, delete it and rewrite from scratch.
Prevention: In code review, watch for sleeps, time-dependent logic, and shared state. Require new tests to pass 10 consecutive runs before merging. Establish clear patterns for async operations (e.g., standard wait helpers).
Trust Recovery
Flaky tests erode trust faster than they can be fixed. If developers start ignoring CI because "it's probably just flaky," the entire suite loses value. Aggressive quarantine and visible metrics keep the suite trustworthy while problems are resolved.
Common Mistakes to Avoid
- Testing only happy paths and neglecting error scenarios
- Creating test cases without clear pass/fail criteria
- Automating everything including expensive, flaky UI tests
- Letting flaky tests accumulate without aggressive remediation
- Viewing QA as a gate rather than a collaborative quality process