Overview
The Ratio of Test Code to System Code metric measures the amount of test code relative to system code in terms of the
number of methods. Constant developer testing should result in at least one test case for each method, and almost
always more than one. As a result, this metric should yield a high value (always more than one, or >1), even in the
early stages of the development lifecycle.
Measurement Method
Ratio of test code to system code = total number of test methods / total number of system
methods
Measurement Analysis
The number of test methods always continues to grow if developer testing is performed while code is written (rather
than waiting to test during integration). The number of test methods should be at least two times the number of
system methods, because for each system method developed, there should be at least a positive test case and a
negative test case. A higher number for this metric indicates a higher level of developer testing.
The following are example scenarios that you can observe using this metric.
Scenario 1: Ideal scenario
In the early stages of development, developers start writing a test case, write code for the particular test case, run
the test, find errors, and fix the code. At this time, you should expect the number of test methods to
be about the same as the number of system methods. The number of system methods should not be greater than
the number of tests (which means that the result of this metric is always greater than one, or >1).
Later in the development lifecycle, the test methods and system methods continue to grow. There are more test
cases written for each system method. At this stage, you would presume that the number of test methods is at
least two to three times larger than the number of system methods.
Scenario 2: Coding without writing a test
At any point during the development lifecycle, if the ratio of test code to system code is less than one
(<1), this is a strong indicator that the code has been written without writing the test cases.
At any point during the development lifecycle, if the ratio of test code to system code drops dramatically from
the last assessment (for example, from five times to two times), it is a sign that source code has been added
without new test cases. Your team should investigate ways to improve the ratio of tests to methods for the next
assessment.
|