Design boundary and equivalence tests for a quantity field.
Instruction: Give concrete inputs and expected results for every boundary and invalid class in the supplied contract.
A fictional order API accepts quantity as a required JSON integer from 1 through 20 inclusive. It rejects null, strings, booleans, fractional numbers, and omitted values without coercion. Invalid input returns a validation error and creates no order. For this exercise, 1.5 is a fractional number; there is no need to decide how a parser represents 1.0. Assume all other fields are valid.
Updated
Example Answer
I would partition the input into valid integers from 1 to 20, integers below the range, integers above it, and the explicitly rejected types or missing value. My boundary set is 0, 1, 2, 19, 20, and 21, with 10 as a typical valid interior value. This checks both sides of each inclusive limit.
I would separately test null, a numeric string, a boolean, a fractional number, and the missing key, because a range check alone can accidentally coerce or accept them. For every invalid case I would assert the validation error and that no order was created. For valid cases I would check the stored quantity, not just a success status.
These examples exercise the stated contract. They do not prove every parser or large-payload behavior; I would add such checks only when that boundary is in scope.
Worked test cases
| Input | Class | Expected result |
|---|---|---|
| 0 | Just below minimum | Reject; no order |
| 1 | Minimum | Accept; store 1 |
| 2 | Just inside minimum | Accept; store 2 |
| 10 | Typical valid value | Accept; store 10 |
| 19 | Just inside maximum | Accept; store 19 |
| 20 | Maximum | Accept; store 20 |
| 21 | Just above maximum | Reject; no order |
| null | Null | Reject; no order |
| "5" | String | Reject; no order |
| true | Boolean | Reject; no order |
| 1.5 | Fractional number | Reject; no order |
| quantity omitted | Missing required field | Reject; no order |
What the interviewer is assessing
Core checks (1 point each):
- Tests valid 1/20 and invalid 0/21 with expected outcomes.
- Includes null, strings, booleans, fractions and omitted-value rejection.
- Checks invalid input creates no order using otherwise-valid fixtures.
Stronger (+1 after all core checks): Includes near-inside boundaries, verifies stored quantities, and notices that booleans may behave like integers in some implementations.
Acceptable alternatives: Separate cases or parameterization work if every class remains observable.
Red flags: Treats the range as exclusive, accepts a numeric string despite the contract, or checks only front-end validation.
Follow-up
Would you run this entire matrix through the browser?
Example response: I would exercise the API contract directly so I can send types the UI cannot create and obtain fast, precise failures. I would also keep a small browser check for field feedback and one successful order. The browser coverage complements the server validation rather than replacing it.
Related Questions
-
easy
-
easy
-
easy
-
easy
-
easy
-
easy