Tests should be easy to write

There should be no friction when it comes to writing tests. If it is hard to do so (perhaps writing an integration test requires you to set up the database, create complex objects one by one, and so on), it is too easy for you to give up and not do it.

Writing unit tests tends to be easy most of the time, but it may get complicated when the class under test requires too much setup or depends on too many other classes. Integration and system tests also require each test to set up and tear down the (external) infrastructure.

Make sure tests are always easy to write. Give developers all the tools to do that. If tests require a database to be set up, provide developers with an API that requires one or two method calls and voilà—the database is ready for tests.

Investing time in writing good test infrastructure is fundamental and pays off in the long term. Remember the test base classes we created to facilitate SQL integration tests and all the POs we created to facilitate web testing? This is the type of infrastructure I am talking about. After the test infrastructure was in place, the rest was easy.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *