Protip for anyone writing tests by Gojko Adzic
Awesome protips to think when we write our tests posted on twitter, thanks a lot Gojko Adzic.
- protip 1: you'll end up reading them a lot more often than writing them, so invest in making tests easy to understand.
- protip 2: define your assertions/expectations first, that will help focus set-ups and avoid shotgun tests.
- protip 3: if it has 'and' in the name, it's too broad, brittle and will prove difficult to maintain.
- protip 4: if a test is hard to write, client code will be too. don't fight the test, improve the API design instead.
- protip 5: avoid waiting for fixed time periods, wait for events instead. tests become less brittle and run faster.