Test Case Design and Edge Case Analysis Questions
Systematically deriving the cases, inputs, and conditions most likely to expose defects. Covers formal test-design techniques (equivalence partitioning, boundary value analysis, decision tables, state transitions, and pairwise/combinatorial design) and writing clear, maintainable test cases with documented expected results. Also covers the edge-case mindset: boundary conditions, invalid and unexpected inputs, corner cases, and the attention to detail that anticipates failures when validating complex behavior.
Discuss limitations and blind spots of property-based testing (PBT), such as difficulty modeling stateful multi-service interactions, non-deterministic IO, and complex performance invariants. For each limitation propose complementary testing techniques and describe how a Solutions Architect should combine them to build robust test coverage.
Sample Answer
Direct answer
Property-based testing (PBT), the technique of asserting general invariants and letting a framework generate many random inputs rather than hand-writing individual example-based cases, has three structural blind spots: it struggles to model stateful interactions across multiple services, it cannot meaningfully generate or reason about non-deterministic I/O, and it does not naturally express complex performance invariants. Each has a complementary technique that covers the gap, and a senior answer's job is knowing which combination to reach for rather than treating PBT as a universal replacement for other testing styles.
Structured elaboration
Stateful multi-service interactions. Classic PBT (a pure function with generated inputs, checked against a property) models a single component's behavior well, but a distributed system's correctness often depends on the interleaving of operations ACROSS services with independent state and independent failure modes, which is a much larger and less tractable generation space than "random valid inputs to one function." Stateful PBT extensions exist (modeling a sequence of commands against an abstract model of the system and checking the real system matches at each step) but scale poorly once more than one or two services are involved, because the state space to explore grows with the product of each service's own state space. Complementary techniques: contract testing (each service's interface is tested against a shared, versioned contract independent of the other services' actual behavior) narrows the cross-service surface to just the interface; and chaos/fault-injection testing at the system level (deliberately injecting latency, partial failures, or partitions between real running services) exercises the actual interleavings PBT cannot economically generate.
Non-deterministic I/O. A property test wants a pure, repeatable relationship between generated input and expected output; a network call, wall-clock read, or unordered concurrent write breaks that repeatability, since the same generated input can legitimately produce different observable results on different runs. PBT frameworks handle SOME non-determinism by controlling it explicitly (a fixed seed for a random-number generator used inside the code under test, a mocked clock), but true external non-determinism (a real network's latency and ordering) isn't something a property assertion can pin down. Complementary techniques: dependency injection of the non-deterministic source (inject a fake clock/network so the "non-determinism" becomes just another generated input PBT CAN control) where feasible, and for the cases where it genuinely cannot be pinned down, invariant-based monitoring in production or in a longer-running integration environment (assert the invariant continuously over real traffic rather than trying to reproduce it from a generated seed).
Complex performance invariants. "This function's output is correct" is a property PBT expresses naturally; "this function's p99 latency stays under a bound as load scales" is not, because performance is an aggregate, environment-dependent property across many calls, not a single input/output relationship, and asserting a specific latency number in a test is explicitly the kind of unreliable, environment-dependent claim a rigorous test suite avoids. Complementary techniques: load/performance testing tools that measure aggregate behavior under controlled load (and assert on RELATIVE regressions or algorithmic complexity, e.g. "doubling input size should not more than double comparison count," rather than absolute wall-clock numbers), and benchmark-based regression tracking over time in a controlled environment rather than as a pass/fail unit-test assertion.
Worked example
A payment-processing change touches three services (an order service, a payment gateway adapter, and a ledger service) and also changes a hot-path calculation function. PBT is the right tool for the calculation function alone: generate a wide range of amounts, currencies, and rounding-edge values and assert the calculation is associative and matches a reference decimal implementation to the cent. It is the wrong tool, on its own, for whether the order service, gateway adapter, and ledger correctly agree after a gateway timeout followed by a retry, since that depends on the actual interleaving of network calls across three independently-deployed services; a contract test asserts the gateway adapter's retry behavior matches its documented interface in isolation, and a chaos test that injects a real timeout between the gateway adapter and the ledger service, run against actual deployed instances (or a realistic staging topology), is what actually exercises the interleaving. Neither the calculation's correctness property nor the cross-service chaos scenario substitutes for the other; a Solutions Architect combining them treats PBT as the tool for the pure computational core and reaches for contract tests and chaos/fault injection specifically at the service boundaries PBT cannot economically reach, rather than trying to stretch one technique to cover every layer.
Trade-offs and pitfalls
The common mistake is treating PBT's blind spots as reasons to avoid it rather than reasons to scope it correctly: PBT genuinely finds edge cases in pure logic that example-based tests miss (a well-known, real strength), and abandoning it because it cannot cover the whole system throws away that strength unnecessarily. The opposite mistake, forcing PBT to cover stateful multi-service behavior via ever more elaborate model-based state machines, tends to produce a test suite that is slow, flaky, and hard to debug when it fails, because the failure could be in the real system, the abstract model, or the generator itself, and untangling which one takes real effort; past a certain system complexity, the return on that effort is lower than building a focused contract test plus a focused chaos scenario. The senior framing is to match each technique to the shape of the risk it is actually good at finding, not to pick one technique as the team's default and stretch it everywhere.
What is mutation testing, and how does it tell you whether your test suite is actually adequate, as opposed to just achieving high line/branch coverage? Give a concrete example of a mutant a coverage-satisfied suite would miss.
Sample Answer
Direct answer
Mutation testing checks test-suite adequacy by deliberately introducing small, mechanical bugs (mutants) into the code under test and re-running the existing suite against each one: if the suite still passes, the mutant SURVIVED, meaning the suite would not have caught that exact bug had a developer introduced it by accident. It answers a fundamentally different question than coverage does: coverage asks whether a line or branch executed; mutation testing asks whether the test's ASSERTIONS were strong enough to notice if that line's logic were wrong, and a suite can score 100% on the first while still missing real bugs the second would catch.
Structured elaboration
The mechanism has three steps: generate mutants by applying a small, well-defined set of operators (flip a comparison operator, change a boundary from > to >=, negate a condition, alter a constant) one at a time to produce many slightly-broken copies of the code; run the existing test suite against each mutant in isolation; and classify each mutant as KILLED (some test failed, proving the suite would notice this exact bug) or SURVIVED (every test still passed, proving it wouldn't). Mutation score is the fraction of mutants killed, and unlike line/branch coverage, it directly measures assertion strength rather than mere execution, because a mutant can only be killed if some test actually CHECKS the specific value the mutation changed, not just runs the code path containing it.
Worked example
def is_discount_eligible(order_total, is_member):
if order_total > 100:
return True
if is_member:
return True
return False
Test suite (3 cases, achieving 100% statement coverage AND 100% branch coverage, run for real):
def run_suite(fn):
r1 = fn(150, False) # order_total > 100 branch TRUE
r2 = fn(50, False) # order_total > 100 FALSE, is_member FALSE
r3 = fn(50, True) # order_total > 100 FALSE, is_member branch TRUE
return bool(r1) == True and bool(r2) == False and bool(r3) == True
This suite passes against the original function, confirmed by execution, and it exercises both outcomes of both if statements, so it is fully branch-covered.
Mutant: order_total > 100 changed to order_total >= 100. Run against the SAME suite: the suite still passes (run_suite(mutant_boundary) returns True), so this mutant SURVIVES, despite full branch coverage. To rule out the alternative explanation (that this mutant simply can never be distinguished from the original, an "equivalent mutant"), the boundary value order_total = 100 was checked directly: the original function returns False at exactly 100 (since 100 > 100 is false and the caller in this check is not a member), while the mutant returns True (since 100 >= 100 is true). The two implementations genuinely disagree at that one input, confirmed by execution, so this is a real, killable-in-principle mutant that survives specifically because the suite never tests order_total == 100.
Trade-offs and pitfalls
The pitfall this example is built to demonstrate directly: a coverage report showing 100% branch coverage says nothing about whether the boundary itself, as opposed to just both SIDES of it, was ever tested. Teams that treat coverage as the finish line routinely ship exactly this kind of off-by-one at a threshold, because both > and >= versions of the function produce identical coverage reports and identical results for every input except the single boundary value. A second, subtler pitfall is mistaking a genuinely surviving mutant for an "equivalent mutant" (one that cannot be killed because it behaves identically for every possible input) without checking; the boundary check above is exactly that verification step, and skipping it risks writing off a real, actionable test gap as unfixable noise.
Compare and contrast equivalence partitioning, boundary value analysis, pairwise (pairwise combinatorial) testing, and exploratory testing. For each technique, describe scenarios in which it provides the most value, its limitations, and provide an example application to a file-upload feature (file size limit, allowed types, network interruptions).
Sample Answer
Direct answer
Equivalence partitioning (EP), boundary value analysis (BVA), pairwise testing, and exploratory testing solve different problems: EP and BVA shrink an infinite input space to a small, defensible set of representative cases; pairwise testing shrinks a combinatorial configuration space; exploratory testing finds the things none of the systematic techniques anticipated.
Structured elaboration
| Technique | Best used when | Limitation |
|---|---|---|
| Equivalence partitioning | A single input has distinct behavior classes (valid range, invalid range, special category) | Assumes every value in a class truly behaves the same; misses interactions between fields |
| Boundary value analysis | The behavior is defined by numeric or ordered limits | Only as good as the boundaries you correctly identify; misses non-boundary logic bugs |
| Pairwise testing | Several independent parameters combine, and full combinatorial testing is infeasible | Only guarantees 2-way interaction coverage; a bug that only appears with 3+ parameters together can be missed |
| Exploratory testing | You need to find the unknown-unknowns, or the system is new/poorly specified | Not repeatable or measurable the same way; coverage depends on the tester's skill and time |
In practice these are complementary, not competing: EP/BVA design the systematic core of a suite, pairwise controls the combinatorial explosion once you have several such inputs interacting, and exploratory testing runs on top to catch what the checklist-driven techniques structurally cannot (workflow surprises, usability issues, timing-dependent bugs).
Worked example: file-upload feature
Assume the feature has a file-size limit of 10 MB, an allowed-type list of {jpg, png, pdf}, and operates over a network that can be interrupted.
- Equivalence partitioning: partition file TYPE into {allowed image, allowed pdf, disallowed type (e.g..exe), no extension}; partition file SIZE into {well within limit, at limit, over limit}. One representative test per partition, e.g. a 2 MB jpg (valid), a 2 MB.exe (invalid type), a 15 MB pdf (invalid size).
- Boundary value analysis: for the 10 MB size limit, test 10 MB - 1 byte, exactly 10 MB, and 10 MB + 1 byte. BVA is the right tool here because the size check is a numeric threshold; EP alone would only tell you to test "one big file," not the exact byte where behavior flips.
- Pairwise testing: if type, size-bucket, and network-condition (stable / interrupted mid-upload) are three independent parameters, pairwise testing picks a small set of combinations (e.g. jpg+at-limit+stable, pdf+over-limit+interrupted, exe+within-limit+interrupted) that cover every pair of parameter values at least once, instead of testing every type x every size-bucket x every network condition.
- Exploratory testing: a tester freely uploads a file, then immediately navigates away, uploads the same filename twice in two tabs, or renames a.exe to.jpg to see if the check is extension-based or content-based. None of the systematic techniques above would generate that renaming trick on their own; it comes from tester intuition about how real users (and attackers) behave.
Trade-offs & pitfalls
A common mistake is treating these as alternatives and picking just one. Relying on EP/BVA alone gives you a clean, explainable suite but nothing that mimics real usage disorder; relying only on exploratory testing gives good bug-finding but poor repeatability and no defensible coverage story for a regression suite. The senior move is to use EP/BVA to build the deterministic regression core, pairwise to keep configuration-heavy features tractable, and time-boxed exploratory sessions to supplement both, then feed anything exploratory testing finds back into the systematic suite as a new equivalence class or boundary.
Describe unit tests (test cases and assertions, not implementation) for a function merge_sorted_arrays(a, b) that merges two sorted integer arrays. Cover empty arrays, single-element arrays, arrays with duplicates, different lengths, and arrays containing negative numbers.
Sample Answer
Direct answer
For merge_sorted_arrays(a, b), the edge cases to cover are both-empty, one-empty, single-element, duplicates (both within and across the two arrays), different lengths, and negative numbers, because each independently exercises a different branch of the two-pointer merge loop; alongside it, linked-list cycle detection is a second classic data-structure edge-case artifact worth pairing with it, because it tests the opposite skill (detecting an ill-formed structure rather than merging two well-formed ones) using the same "trace pointer movement by hand" reasoning discipline.
Structured elaboration
A standard two-pointer merge (i, j walking a and b, appending the smaller front element, then draining whichever array has leftovers) has three places a bug commonly hides:
- The loop-exit condition (
while i < len(a) and j < len(b)): if one input is empty, the loop body never runs, so ALL correctness has to come from the drain step (out.extend(a[i:]),out.extend(b[j:])) after the loop, not the loop itself. Both-empty and one-empty tests specifically exercise this drain path. - The tie-breaking comparison (
a[i] <= b[j]vsa[i] < b[j]): using strict<instead of<=still produces a correctly SORTED result on duplicate values, but silently reorders which array's copy of a tied value comes first, which matters if the merge needs to be stable (e.g. preserving a secondary sort key attached to each element). - The negative-number case doesn't exercise different code than positive numbers in a correct implementation, but it is a high-value test anyway because it catches implementations that reach for an unsigned-length-based trick (e.g. treating array length or magnitude as a sentinel) instead of a pure comparison-based merge.
Linked-list cycle detection (Floyd's slow/fast pointer technique) is a different function entirely, but belongs in the same edge-case-design conversation because its edge cases follow the identical decomposition logic: empty structure, single-node structure, and "does the malformed case actually loop the way you think it does" (a self-loop where a single node points to itself, versus a cycle that starts partway through the list rather than at the head).
Worked example (executed)
def merge_sorted_arrays(a, b):
i, j = 0, 0
out = []
while i < len(a) and j < len(b):
if a[i] <= b[j]:
out.append(a[i]); i += 1
else:
out.append(b[j]); j += 1
out.extend(a[i:])
out.extend(b[j:])
return out
class ListNode:
def __init__(self, val, next=None):
self.val = val
self.next = next
def has_cycle(head):
slow = fast = head
while fast is not None and fast.next is not None:
slow = slow.next
fast = fast.next.next
if slow is fast:
return True
return False
| Function | Test | Input | Expected |
|---|---|---|---|
merge_sorted_arrays | both empty | [], [] | [] |
merge_sorted_arrays | one empty | [], [1,2,3] | [1,2,3] |
merge_sorted_arrays | single-element | [5], [3] | [3,5] |
merge_sorted_arrays | duplicates (across and within) | [1,2,2], [2,2,3] | [1,2,2,2,2,3] |
merge_sorted_arrays | different lengths | [1,5,9], [2,3] | [1,2,3,5,9] |
merge_sorted_arrays | negative numbers | [-5,-1,3], [-4,0,2] | [-5,-4,-1,0,2,3] |
has_cycle | empty list (head=None) | None | False |
has_cycle | single node, no cycle | one ListNode | False |
has_cycle | single node, self-loop | node.next = node | True |
has_cycle | cycle partway through a 4-node list | last node points back to node 2 | True |
All 10 tests executed with pytest: 10 passed in 0.01s.
Trade-offs and pitfalls
For the merge function, the most common wrong turn is testing only "different-length, no duplicates" happy-path inputs and treating that as sufficient because the algorithm LOOKS simple; the duplicate-across-arrays case specifically catches an off-by-one in whichever array's pointer advances first on a tie. For cycle detection, the common wrong turn is testing only a cycle that starts at the head, which passes even for a broken implementation that (incorrectly) checks slow == head instead of slow is fast; a cycle that starts partway through the list, as tested here, is the case that actually forces the fast/slow pointers to meet somewhere other than the entry node, proving the algorithm's core invariant rather than a coincidental match.
Describe a structured checklist or template you would use to enumerate boundary and off-by-one conditions for a new feature. Include at least ten checklist items that cover ranges (inclusive/exclusive), minimum/maximum values, zero and single-element cases, negative and sentinel values, date/time boundaries, integer limits, floating-point boundaries, indexing, and I/O limits. Explain how you'd apply this checklist during requirements review and when writing test cases.
Sample Answer
Direct answer
A reusable boundary/off-by-one checklist should walk through every dimension a value or collection can have an edge at: the range itself (inclusive/exclusive), the extremes (minimum/maximum), the degenerate cases (zero and single-element), unusual-but-valid values (negative numbers, sentinel values), and the domains where boundaries are especially easy to get wrong (dates/times, integer limits, floating-point precision, indexing, and I/O size limits).
Structured elaboration: the ten-plus checklist items
- Range inclusivity: for every stated range ("between X and Y"), confirm explicitly whether both ends are included, and test the boundary value itself, not just values near it.
- Minimum value: the smallest value the field/collection is documented to accept.
- Maximum value: the largest value the field/collection is documented to accept.
- Just below minimum / just above maximum: the immediately-invalid neighbors, to confirm the boundary is actually enforced, not off by one.
- Zero: for any numeric field, does zero mean 'none', 'unlimited', or an ordinary valid value? This is frequently ambiguous and worth pinning down explicitly.
- Single-element case: for any collection, list, or array, the one-element case often reveals loop or indexing bugs invisible in either the empty or many-element case (e.g. a loop that assumes at least two elements to compare adjacent pairs).
- Negative values: even for a field that 'should never' be negative, confirm what actually happens if it is, since the type system alone rarely prevents it.
- Sentinel values: reserved special values used to mean something other than their literal value (-1 for 'not found', 999999 for 'unknown', an empty string for 'unset'); confirm the sentinel doesn't collide with a legitimate value.
- Date/time boundaries: month-end, year-end, leap years, daylight-saving-time transitions, and the exact instant of a stated cutoff (e.g. "expires after 30 minutes" needs a test at exactly 30:00, not just 29:59 and 30:01).
- Integer limits: the type's maximum/minimum representable value (e.g. 2^31-1 for a 32-bit signed integer), and what happens one step beyond it.
- Floating-point boundaries: values very close to zero, very large magnitudes, and the classic non-exact-representation trap (does an equality check tolerate representation error, or not).
- Indexing: the first index, the last index, and one-past-the-last-index (a frequent off-by-one source in loop bounds).
- I/O limits: the maximum request/response/file size a system will accept, and what happens exactly at and just past that limit.
Worked example: applying the checklist during requirements review
During a requirements review for a new 'bulk import' feature accepting up to 10,000 rows per file, walking this checklist against the requirement surfaces several questions the requirement itself doesn't answer: is 10,000 inclusive (does row 10,000 succeed)? What happens with a 0-row file (empty, item 6)? Is there a MINIMUM row count, or is 1 row valid (item 2/6)? What happens to row 10,001 in a same-request bulk import (item 4)? These become explicit, answered acceptance criteria BEFORE implementation starts, rather than ambiguities discovered during test-case writing after the fact, which is a meaningfully cheaper time to resolve them.
Applying it when writing test cases
Once the requirement is unambiguous, each checklist item that applies to the feature becomes a candidate test case directly: the checklist's job at this stage shifts from 'surface ambiguity' to 'ensure nothing on this list was silently skipped', functioning as a coverage audit against the test suite that already exists rather than a fresh brainstorm every time.
Trade-offs & pitfalls
A checklist applied mechanically to every field regardless of relevance produces test-case bloat (testing floating-point-precision boundaries on a field that is always an integer wastes effort); the checklist's value is in prompting the QUESTION for every dimension, with the judgment to skip items that are genuinely inapplicable to a given field, not in guaranteeing every item becomes a test case every time.
Unlock Full Question Bank
Get access to all Test Case Design and Edge Case Analysis interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.