Keep test code and application code separate

by Jason Swett,

Sometimes you’ll be tempted to add things to your application code that don’t affect the functionality of your application but do make testing a little easier.

The drawback to doing this is that causes your application code to lose cohesion. Instead of doing just one job—making your application work—your code is now doing two jobs: 1) making your application work and 2) helping to test the application. This mixture of jobs is a straw on the camel’s back that makes the application code just that much harder to understand.

Next time you’re tempted to add something to your application code to make testing more convenient, resist the temptation. Instead add it somewhere in the code that supports your tests. This may take more time and thought initially but the investment will pay itself back in the long run.

Leave a Reply

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