Agent Wranglers

TST-3Recommended

Ship tests in the same change

Every change that adds or changes behaviour includes the tests for it. A bug fix starts with a test that fails before the fix.

How to do it

Write or update the test in the same pull request as the code. For a bug, first write a test that reproduces it and watch it fail. Then fix the code and watch it pass. Reviewers reject changes to behaviour that come without tests. Security fixes follow the same rule, as Turn every fix into a check says.

Examples

Python example

# Bug: a cart with only free items charged a 5.00 shipping fee
def test_free_cart_has_no_shipping_fee():
    cart = Cart(items=[Item(price=0)])
    assert cart.shipping_fee() == 0

TypeScript example

// Bug: a cart with only free items charged a 5.00 shipping fee
test('a free cart has no shipping fee', () => {
  const cart = new Cart([{ price: 0 }]);
  expect(cart.shippingFee()).toBe(0);
});

How to check

In review, revert the code change but keep the test. The new test fails. Restore the code, and it passes.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/testing/test-strategy/tests-with-the-change">Agent Wranglers testing playbook</a>. In code you write, add a comment next to it with the same link.