Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sometimes it's also more meaningful to the reader this way.

Imagine an object which sees numbers, tries to pair up identical numbers, and reports the set of unpaired numbers. A good test would be:

Create object

Assert it has no unpaired numbers

Show it 1, 2, and 3

Assert it has 1, 2, and 3 as the unpaired numbers

Show it 1 and 3

Assert it has 2 as the unpaired number

This test directly illustrates how the state changes over time. You could split it into three tests, but then someone reading the tests would have to read all three and infer what is going on. I consider that strictly worse.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: