Two more neat things about automated tests

You’re probably already aware of some of the reasons Test-Driven and Behaviour-Driven Development (“TDD” and “BDD”) are Good Things:  You can refactor safely, you know when you’ve finished a feature (because all your tests pass), you can add new features without breaking existing functionality, it’s easier to allow others to contribute to your projects and so on.

Here’s a couple you may not have considered, though.  Both of these advantages of TDD/BDD will help you if you return to a codebase after a break and can’t remember how everything works, or if you’re a new developer on a project and don’t understand all the details.

First off, your tests themselves can help you understand the system better — the tests can provide a way of documenting how the system works (especially with BDD).

And secondly, your automated tests will make it easier for you to manually check and test your system in future, even if you’ve forgotten the detail of how it works or how to use it!

Consider the following example:  You have a class which generates reports.  These reports have 5 different sections which may be present in any combination (all, none or some), depending on the values of various parameters, database entities and so on.  You want to change something about the display of the reports and check that this change looks right with all these combinations.

If your project didn’t have tests, you’d have a long and painful trawl through the code to work out what properties and values need setting in order to produce the different combinations of sections in a report.  And you’ll then have to get the system into the state required by each situation — hacking away to hard-code settings, adding new entities to your database, and so on.  Boring!

But if your project does have thorough tests, then you can see right there in the tests what preconditions are needed for each situation, giving you the understanding you need easily!  And if you need to manually check the output for each situation (as in the example above), you can just run the tests!  (You might need to tweak the tests to explicitly show output, of course, but that’s usually trivial).

Hopefully this example shows how automated testing can teach you how a complicated system works and can also support your manual testing, saving you a lot of effort in reproducing complicated situations.  Excellent!

Post a Comment

Your email address is never published nor shared. Required fields are marked *

Ready to talk?

Whether you want to create a new digital product or make an existing one even better, we'd love to talk it through.

Get in touch