Coding Practice: Unit Test to Code Ratio

Coding Practice: What should I do if my lines of unit test code is greater than the lines of code being tested?
This is a good sign.  You should expect to have a code-to-test ratio of 1:2 (i.e. twice as much unit test code as actual code).  If you don’t have more test code than production code, then you are probably too light on tests.

“By necessity each unit of functionality has at least one test. For many types of functionality, one test is not enough.  Tests that test only the ‘happy path’ of your code are easy to write.    Unfortunately, these tests often do not tell the whole story.”
–            James Bender

Keep in mind, when you are doing TDD, you will create at least one “happy path” and one boundary unit test per class method, so from the very outset you will have more test code than production code.  As you add functionality, you will think of additional functional and non-functional requirements to represent as unit tests and additional boundary tests which will result in a code-to-test ratio of around 1:2.

Professional Test Driven Development with C#

About Chris VanHoose

Principal Software Architect at CT Lien Solutions
This entry was posted in Software Architecture and tagged , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.