Structured Testing
Structured testing is a white-box unit testing
technique for identifying test cases that identify defects
involving the logic of a functional unit of software.
Structured testing is the traditional primary testing
technique for procedural units of software and for logically
complex methods of object-oriented software. Structured testing
guarantees branch coverage, and thus also guarantees statement
coverage.
The typical objectives of structured testing are to:
- Ensure adequate testing of complex operations.
- Cause failures due to logic (e.g., branching, looping)
defects.
Structured testing can typically begin when the following
preconditions hold:
- The tester(s) has been trained in structured
testing.
- The class under test has been implemented.
Structured testing is typically complete if the following
postconditions hold:
- Branch coverage has been achieved by creating and
executing a test case for each basis path through each
operation with branching and looping.
During structured testing, the unit testers typically
perform the following steps:
- Identify operations with branching and looping.
- For each such operation, determine the McCabe's
cyclometric complexity (i.e., the number of test cases):
- Draw a control flow graph that shows the branches and
loops of the method.
- Calculate the cyclometric complexity by C = e - n + 2,
whereby e is the number of edges and n is the number of
nodes in the control flow graph.
- Identify a set of basis paths through the operation,
whereby the number of basis paths equals McCabe's cyclometric
complexity
- Develop a test case for each basis path by picking
message parameters and states that cause the execution of the
operation to follow the basis path.
Structured testing typically results in the following work
products:
- Test suites containing basis path test cases for each
operation having brancing and/or looping.
Structured testing is typically subject to the following
limitations:
- This technique used to be more important when procedures
contained large amounts of branching and looping; the advent
of inheritance, polymorphism, and refactoring has limited its
value when applied to the small, simple methods of
object-oriented software.
Guidelines
- Try to reuse equivalence set test cases that traverse the
basis paths.
- Basis path testing can be used to identify equivalence
sets.
- Do not rely solely on structured testing, because it is
no longer as important as it once was.
- Polymorphism testing replaces much of what used to be
tested using structured testing.