Prompted by Szczepan’s post.
I have written tests after code when
- the code is already there, but I / others don’t know what it does or how to use it, and we need to
- I wrote a spike which turned out to be pretty good code, and I wanted to describe what it does and how to use it
- I realised I needed to add some simple yet important behaviour while making a different test pass, and forgetting to add the code would possibly introduce serious bugs, so I added it as I went along and now I’m going back to show what it does and how to use it
- I was learning how to write the tests first, and wanted to know what they would look like.