Unit tests Required
Test the edges and the errors
For every rule with a limit, test the values on both sides of it. For every input that can be rejected, test the rejection.
How to do it
List the limits of the rule, such as a minimum order, a date range or a maximum length. Test the last value inside each limit and the first value outside it. Add empty input, zero, negative numbers, missing fields and the largest allowed size. Test each error the function can raise, and check its type and message. Use the runner's table of cases, such as test.each or pytest.mark.parametrize, so each case names itself in the report.
Example
// Free shipping from 50.00, in cents
test.each([
[4999, 495],
[5000, 0],
[0, 495],
])('an order of %i cents pays %i cents shipping', (total, fee) => {
expect(shippingFee(total)).toBe(fee);
});
test('a negative total is rejected', () => {
expect(() => shippingFee(-1)).toThrow(RangeError);
});
@pytest.mark.parametrize("total, fee", [(4999, 495), (5000, 0), (0, 495)])
def test_shipping_fee_at_the_free_shipping_limit(total, fee):
assert shipping_fee(total) == fee
def test_a_negative_total_is_rejected():
with pytest.raises(ValueError, match="total"):
shipping_fee(-1)
How to check
Each limit in the code has a test at the limit and one past it. Moving a limit by one, such as >= to >, makes a test fail. Mutation testing finds this mechanically.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/unit-tests/test-the-edges.