Unit Testing: Rules of Thumb

When it comes to testing, Cedric Beust (co-author of “Next Generation Java Testing”) lives by the following rules of thumb:

  • “Tests first” or “tests last” is unimportant as long as there are tests.
  • Try to think about testing as early as possible in your development process.
  • Don’t listen to people who tell you to write “the simplest possible thing that could possibly work”, also known as YAGNI. If your experience tells you you’re going to need this extra class in the future even if it’s not needed right now, follow your judgement and add it now.
  • Keep in mind that functional tests are the only tests that really matter to your users. Unit tests are just a convenience for you, the developer. A luxury. If you have time to write unit tests, great: they will save you time down the road when you need to track bugs. But if you don’t, make sure that your functional tests cover what your users expect from your product.
  • Don’t feel bad if you are not doing Test-Driven Development. There are a lot of factors that make this practice a bad fit for a lot of projects and developer personalities (aspects which are very often never mentioned by TDD extremists).

From TDD leads to an architectural meltdown around iteration three, by Cedric Beust.

Advertisements

2 thoughts on “Unit Testing: Rules of Thumb

  1. Good list. I’m still mulling over the caution about YAGNI. I think its validity might be contingent on the maturity of the individual developer.

  2. If you are not using “Test-Driven Development” then you will pay in the long run once the code goes into production. Whether it is during enhancements, refactoring, or bug fixes, the costs will add up over time. Sure you can develop without them, but then I hope you don’t hand the junk off to someone else.

    In my experience, maintaining an application without unit tests is extremely difficult and time consuming. It’s completely inefficient unless you wrote the code yourself.

    The reason for “Test-Driven Development” is far more reaching then just the development life cycle. You need to years into the future and tabulate those costs.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s