Answer prose round 1: 0 🔴, 2 🟡 (0 misread); lead with the condition, split off the timeout, name each example's parts
This commit is contained in:
@@ -62,7 +62,7 @@
|
||||
- Every escaped bug becomes a test that fails without its fix.
|
||||
- Write no test that no real bug could fail: a constant's value, a list's length, the framework's own behaviour.
|
||||
- A test neither sleeps nor asserts on the wall clock, and seeds any randomness.
|
||||
- A test that reads state another goroutine, process or queue sets waits on a signal that the code under test or its fake sends, such as a channel or a callback, with a timeout that only fails the test. Reading the state straight after the call races with the other side, and a sleeping poll breaks the rule above. BANNED: `assert len(server.connections) == 3` right after the client calls. GOOD: the fake sends on a channel per connection, and the test receives three times, with a timeout.
|
||||
- When another goroutine, process or queue sets the state a test reads, the test waits for a signal that the code under test or its fake sends, such as a message on a channel or a callback. Give the wait a timeout whose only effect is to fail the test when the signal never comes. Reading the state straight after the call that starts the work races with that work, and polling with sleeps breaks the rule above. BANNED: `assert len(server.connections) == 3` right after the client opens three connections. GOOD: the fake server sends on a channel each time it accepts a connection, and the test receives from that channel three times, each receive with a timeout.
|
||||
- For pure logic over many inputs, prefer a property test: a round trip, an invariant.
|
||||
- Changing tests and changing other code are two separate processes — be very careful about doing both at once.
|
||||
- Use properly randomised UUID v7s — never `aaaa-0000`-style placeholders.
|
||||
|
||||
Reference in New Issue
Block a user