Software Engineering – Software Testing Techniques FUNDAMENTALS The goal of testing is to find errors. A good test is one that has a high probability of finding an error. A good test is not redundant A good test should be neither too simple nor to complex.
White box testing is sometimes called glass box testing.
White box testing uses the control structure described as part of the component level design to derive test cases.
Using white box testing methods, the software engineer can derive test cases that:
guarantee that all independent paths within a module have been exercised at least once.
exercise all logical decisions on their true and false sides.
execute all loops at their boundaries and within their operational bounds
exercise internal data structures to ensure their validity.
Software Engineering – Software Testing Techniques BASIS PATH TESTING The basis path method enables the test case designer to derive a logical complexity measure of a procedural design and use this measure as a guide for defining a basis set of execution paths. Test cases derived to exercise the basis set are guaranteed to execute every statement in the program at least one time during testing.
Software Engineering – Software Testing Techniques BASIS PATH TESTING FLOW GRAPH NOTATION A flow graph depicts logical control flow using the notation shown below: Each structured construct corresponds to a flow graph symbol.
Software Engineering – Software Testing Techniques BASIS PATH TESTING Flow charts and flow graphs correspond to one another. The flow chart depicts the program control structure. The flow graph assumes no compound structures.
Software Engineering – Software Testing Techniques BASIS PATH TESTING Flow charts and flow graphs correspond to one another. Each circle, called a flow graph node, represents one or more procedural statements. A sequence of process boxes and a decision diamond can map to a single node. The arrows of a flow graph, called edges or links, represent flow of control. An edge must terminate at a node. Areas bounded by edges are called regions.
Software Engineering – Software Testing Techniques BASIS PATH TESTING Compound Conditions Compound Conditions occur when one or more Boolean operators (OR, AND, NAND, NOR) is/are present in a conditional statement. IF A OR B is represented as follows: FIGURE 14.3
Software Engineering – Software Testing Techniques BASIS PATH TESTING Independent Program Paths An independent program path is any path through the program that introduces at least one new set of processing statements or a new condition. When stated in terms of a flow graph, an independent path must move along at least one edge that has not been traversed before the path is defined. For example, a set of independent paths for the flow graph illustrated in Figure 14.2b is: Path 1: 1-11 Path 2: 1-2-3-4-5-10-1-11 Path 3: 1-2-3-6-8-9-10-1-11 Path 4: 1-2-3-6-7-9-10-1-11 Each new path introduces a new edge. Note the following path is not independent: 1-2-3-4-5-10-1-2-3-6-8-9-10-1-11
Software Engineering – Software Testing Techniques BASIS PATH TESTING A basis set for a flow graph is the set of paths that cover every statement in the program. Therefore Paths 1, 2, 3, & 4 are the basis set for the previous figure. If tests are designed to force execution of these paths, every statement is guaranteed to execute at least one time. Every condition will have been executed on its true and false sides. Note, a basis set is not unique. A number of basis sets may be derived from a procedural design. How do we know how many paths to look for?
Cyclomatic complexity is a software metric that provides a quantitative measure of the logical complexity of a program.
When used in the context of the basis path testing method, the value computed for cyclomatic complexity defines the number of independent paths in the basis set of a program and provides an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once.
Cyclomatic complexity is computed a number of ways:
The number of regions corresponds to the cyclomatic complexity.
Cyclomatic complexity, V(*G), for a flow graph G, is defined as: V(G) = E – N + 2, where E is the number of flow graph edges, and N is the number of flow graph nodes.
Cyclomatic complexity, V(G), for a flow graph G, is defined as: V(G) = P + 1, where P is the number of predicate nodes contained in the flow graph G.
Software Engineering – Software Testing Techniques BASIS PATH TESTING Prepare test cases that will force execution of each path in the basis set.
Software Engineering – Software Testing Techniques CONTROL STRUCTURE TESTING Condition Testing Condition Testing is a test case design method that exercises the logical conditions contained in a program module. A simple condition is a Boolean variable or a relational expression, possibly preceded with one NOT operator. A relational expression takes the form E 1 <relational-operator> E 2 Where E1 and E2 are arithmetic expressions and <relational-operator> is one of the following <, <=, =, <>, > or >=. A compound condition is composed of two or more simple conditions, Boolean operators, and parentheses. Boolean operators allowed in a compound condition include OR, AND, and NOT. Errors are much more common in the neighborhood of logical conditions than they are in the locus of sequential programming
Software Engineering – Software Testing Techniques CONTROL STRUCTURE TESTING Loop Testing Four different classes of loops: Figure 14.7
If we extended the simple loop test cases to nested loops, the number of tests would grow geometrically.
Instead use the following scheme:
Start at the innermost loop. Set all other loops to their minimum values.
Conduct simple loop tests for the innermost loop while holding the outer loops at their minimum iteration parameter. Add other tests for out-of-range or excluded values.
Work outward, conducting tests for the next loop, but keeping all the other outer loops at minimum values and other nested loops to “typical” values.
Continue until all loops have been tested.
Software Engineering – Software Testing Techniques CONTROL STRUCTURE TESTING Concatenated Loops Concatenated loops can be tested using the approach defined for simple loops, if each of the loops is independent of each other. If the two loops are concatenated and the loop counter for loop 1 is used as an initial value of loop 2, then the loops are not independent. Unstructured Loops Whenever possible, this class of loops should be redesigned to reflect the use of the structured programming constructs.
Software Engineering – Software Testing Techniques BLACK BOX TESTING Black box testing is also called behavioral testing. Black box testing focuses on the functional requirements of software. Black box testing consists of a set of input conditions that will fully exercise all the functional requirements for a program.
A great number of errors occur at the boundaries of the input domain rather that in the “center”
Boundary value analysis is a test case technique that compliments equivalence partitioning. Rather than selecting any element of the equivalence class, BVA leads to the selection of test cases at the “edges” of the class.
Guidelines are as follows:
If an input condition specifies a range bounded by values a and b, test cases should be designed with values a and b as well as just above and just below a and b.
If an input condition specifies a number of values, test cases should be developed that exercise the minimum and maximum numbers.
If internal program data structures have prescribed boundaries (e.g. an array has a defined limit of 100 entries), be certain to design a test case to exercise the data structure at its boundaries.