1 comment

[ 3.2 ms ] story [ 9.9 ms ] thread
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.