Structured Testing - McCabe and Associates
Structured Testing - McCabe and Associates
Structured Testing - McCabe and Associates
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Consideration of the intent behind complexity limitation can keep st<strong>and</strong>ards policy on track.<br />
There are two main facets of complexity to consider: the number of tests <strong>and</strong> everything else<br />
(reliability, maintainability, underst<strong>and</strong>ability, etc.). Cyclomatic complexity gives the number<br />
of tests, which for a multiway decision statement is the number of decision branches. Any<br />
attempt to modify the complexity measure to have a smaller value for multiway decisions will<br />
result in a number of tests that cannot even exercise each branch, <strong>and</strong> will hence be inadequate<br />
for testing purposes. However, the pure number of tests, while important to measure <strong>and</strong> control,<br />
is not a major factor to consider when limiting complexity. Note that testing effort is<br />
much more than just the number of tests, since that is multiplied by the effort to construct each<br />
individual test, bringing in the other facet of complexity. It is this correlation of complexity<br />
with reliability, maintainability, <strong>and</strong> underst<strong>and</strong>ability that primarily drives the process to<br />
limit complexity.<br />
Complexity limitation affects the allocation of code among individual software modules, limiting<br />
the amount of code in any one module, <strong>and</strong> thus tending to create more modules for the<br />
same application. Other than complexity limitation, the usual factors to consider when allocating<br />
code among modules are the cohesion <strong>and</strong> coupling principles of structured design: the<br />
ideal module performs a single conceptual function, <strong>and</strong> does so in a self-contained manner<br />
without interacting with other modules except to use them as subroutines. Complexity limitation<br />
attempts to quantify an “except where doing so would render a module too complex to<br />
underst<strong>and</strong>, test, or maintain” clause to the structured design principles. This rationale provides<br />
an effective framework for considering exceptions to a given complexity limit.<br />
Rewriting a single multiway decision to cross a module boundary is a clear violation of structured<br />
design. Additionally, although a module consisting of a single multiway decision may<br />
require many tests, each test should be easy to construct <strong>and</strong> execute. Each decision branch<br />
can be understood <strong>and</strong> maintained in isolation, so the module is likely to be reliable <strong>and</strong> maintainable.<br />
Therefore, it is reasonable to exempt modules consisting of a single multiway decision<br />
statement from a complexity limit. Note that if the branches of the decision statement<br />
contain complexity themselves, the rationale <strong>and</strong> thus the exemption does not automatically<br />
apply. However, if all branches have very low complexity code in them, it may well apply.<br />
Although constructing “modified” complexity measures is not recommended, considering the<br />
maximum complexity of each multiway decision branch is likely to be much more useful than<br />
the average. At this point it should be clear that the multiway decision statement exemption is<br />
not a bizarre anomaly in the complexity measure but rather the consequence of a reasoning<br />
process that seeks a balance between the complexity limit, the principles of structured design,<br />
<strong>and</strong> the fundamental properties of software that the complexity limit is intended to control.<br />
This process should serve as a model for assessing proposed violations of the st<strong>and</strong>ard complexity<br />
limit. For developers with a solid underst<strong>and</strong>ing of both the mechanics <strong>and</strong> the intent<br />
of complexity limitation, the most effective policy is: “For each module, either limit cyclomatic<br />
complexity to 10 (as discussed earlier, an organization can substitute a similar number),<br />
or provide a written explanation of why the limit was exceeded.”<br />
16