Michael McDonald's Blog

Keep your unit tests separate

Keep your unit tests separate from your regular code. This includes any frameworks, stubs, skeletons and other supports that you use for testing. Here's why:

  • You can easily exclude test code from production releases. This makes production releases smaller and eliminates that nagging feeling when you have 100MB of test code testing 10MB of real code.
  • Your regular code should remain elegant, preferring fewer classes and managing complexity via abstractions and design patterns. Test code is more use-case oriented, so you keep adding tests over time. These styles have different 'scents': test code mixed among regular code looks like cruft and adding tests looks 'messy'. By keeping them separate, adding tests feels more natural, and refactoring your regular code feels more natural.

I.e. by keeping regular code and test code separate and recognizing the different approaches to them, you encourage more testing and more refactoring.

link  |   |  9/21/07 01:00pm
 
home  |  acting  |  blog  |  consulting  |  noel  |  contact
© 2013 Michael McDonald, . All rights reserved.