Test Patterns

12 thoughts
last posted Sept. 12, 2014, 9:50 p.m.

1 earlier thought

0

What To Test?

How do you decide what to test?

Test every line of code you intend to keep. By "intend to keep", I mean, check in to version control. (Or, if you are in a dysfunctional environment that runs code that isn't in version control, any code you will email to a colleague or save on a production server or otherwise keep around.)

This sounds a little glib, but actually it's an important part of how tests influence design.

If you care that something keeps working, then you should write a test for it. Of course, if you don't care whether it works or not, then you can just skip writing it, and save yourself the time!

This rule has a caveat - the "intend to keep" part - for a reason, though. Some snippets of code are things that you write in order to figure out how something works, or a script that you will literally run once and then throw away. Assuming you have the conviction to actually throw it away, then it would often be a waste of time to verify that it really works right, if the act of running it is itself that verification.

10 later thoughts