Eighteen months in and nobody has ever actually taught me how to write a test
My bootcamp covered testing for about a day. My current job has a big test suite that I mostly copy-paste from. Find a similar existing test, change the names, change the assertions, hope CI stays green.
I can tell that isn't the same as understanding it. Someone asked me in review why I was mocking a particular thing and I genuinely had no answer beyond "the other test did it."
Is there a decent path into this that isn't a twelve-hour course I won't finish? Or is this one of those things where you just write bad tests for a year until they slowly get less bad?
3 comments
- 0
AnonymousAnon Very practical suggestion: next time you copy a test, delete one assertion and run it. If it still passes, that assertion was never testing anything.
Doing that a dozen times across our suite taught me more about what a test is actually for than anything I'd read. It also turned up a few tests of ours that assert essentially nothing.
- 0
AnonymousAnon You're not behind. Most teams teach testing by osmosis and then act surprised that it didn't take.
The thing that made it click for me was asking, for every mock, "what am I pretending doesn't exist right now, and why?" If you can't answer that in one sentence, the mock is usually wrong or unnecessary. That one question replaced about six hours of course material for me.