

I suck at writing unit tests, but I'm trying to change - 1kevgriff
http://kevgriffin.com/i-suck-at-writing-unit-tests/

======
geebee
The advice I've always given people is to realize that they're already
testing, and that they should just keep those tests rather than throw them
away.

If you're writing a function to do a calculation, you almost certainly create
a little script to call it and make sure it's working correctly, right? Well,
don't just do it with irb (or whatever), put it in a directory called tests,
and set it to run automatically. If you change it and it breaks at some point,
you'll be alerted to the problem.

Now, if to run a test, you instead fire up a server, click or type on a page,
and check output, automate that process and put it in test folder.

Here's the problem - sometimes the tools are designed so that it's far easier
to fire up the server and do this manually than it is to automate it. This
creates a problem, since writing tests should be as easy (or easier) than
doing things manually. When this happens, yeah, your tools are tempting you to
not write tests.

At that point, unfortunately, you do need to bring a bit of personal
discipline to it, as well as sometimes push back against clients or managers
who are tapping their fingers impatiently about features. And while people
_should_ write tests, I can't exactly act all surprised and appalled if they
don't.

