Slide3 Testing Strategies - White Box
Slide3 Testing Strategies - White Box
The full list of paths (there are 24 paths required for full path coverage)
Path Coverage Criteria
X, c-use X, p-use
Data-Flow Based White Box Testing
Techniques
• Date-flow based test adequacy criteria can be defined based on coverage goals in
terms of variable uses:
• All def
• All p-uses
• All c-uses/some p-uses
• All p-uses/some c-uses
• All uses
• All def-use paths
• The strongest criterion is all def-use paths.
• We refer to a path from a variable definition to a use as a def-use path.
Data-Flow Based White Box Testing
Techniques
• To satisfy all def-use criterion, the tester must identify and classify occurrences
of all the variables in the SUT. A tabular summary is useful.
• Then for each variable, test data is generated so that all definitions and all uses
for all of the variables are exercised during test.
Data-Flow Based White Box Testing
Techniques
Example
Data-Flow Based White Box Testing
Techniques
Example
Data-Flow Based White Box Testing
Techniques
Example
Data-Flow Based White Box Testing
Techniques
Example
• The following set of test inputs cover all the def-use pairs for the variables:
Data-Flow Based White Box Testing
Techniques
• As with most white box testing methods, the data flow approach is most effective
at the unit level of testing.
• Data-flow analysis can become time consuming when code becomes more
complex and there are more variables to consider.
• Tool support for data-flow based testing is currently limited.
Loop Testing
• Loops are among the most frequently used control structures.
• Many defects are associated with loop constructs.
• Loops can be classified into four categories:
Simple Nested Concatenated Unstructured
Loop Testing
• A strategy for testing a simple loop that can have a range of zero to n iterations:
• Develop test cases so that there are:
Loop Testing
• A strategy for testing nested loops:
• Set the outer loop control variable(s) to the minimum value(s).
• Test the innermost loop using the strategy for testing simple loops.
• Perform test for the next loop and work outward.
• Continue until the outmost loop has been tested.
Loop Testing
• A strategy for testing concatenated loops : 1
• If the two loops are independent of each other then they are individually tested using simple
loops.
• However, if the loop counter for one loop is used as the initial value for the second loop, then
these loops should not be considered as independent loops.
• In this case, these loops should be tested as nested loops.
1
https://www.guru99.com/loop-testing.html
Loop Testing
• Unstructured loops should be redesigned to reflect the use of the structured
programming constructs.
Loop Testing
• A loop count adequacy criterion can be defined in terms of the number of
iterations executed in the case of a loop having a maximum of n iterations.
• Loop testing usually suffers from the large number of tests needed.
Mutation Testing
• The approaches discussed so far focus on code behavior and code structure.
• Mutation testing is another approach that requires knowledge of code structure
but is classified as a fault-based testing approach.
• It considers the possible faults that could occur in a SUT as the basis for test data generation
and evaluation of testing effectiveness.
Mutation Testing
• Mutation testing starts with a code component, its associated test cases, and the
test results.
• The original code component is modified in a simple way to provide a set of
similar components that are called mutants.
• Each mutant contains a fault as a result of the modification.
• The original test cases are run with the mutants:
• If a test case reveals the fault in the mutant by producing a different output as a result of
execution, then the mutant is said to be killed.
• If the test cases do not produce outputs that differ from the original, then the test set is not
capable of revealing such defects. In this case, the tests cannot distinguish the original from
the mutant. The tester then must develop additional test cases to reveal the fault and kill the
mutant.
Mutation Testing
• A test adequacy criteria for mutation testing is the following:
Mutation Testing
• A mutation is a simple change in the original code component, for example:
constant replacement, arithmetic operator replacement, data statement
alteration, statement deletion, and logical operator replacement.
Consider the following simple changes:
- In Line 7, change i= i + 1 to i = i + 2
If we re-run the tests used for branch
coverage, this mutant would be killed.
- In Line 5, change if a[i]>0 to if a[i]<0
If we re-run the tests used for branch
coverage, this mutant would be killed.
- In Line 5, change if a[i]>0 to if a[i]>=0
This mutant would not be killed by our original
test data. We need to augment the test cases
with a new case that includes a zero in a[0].
However, even this new case would not cause
the mutant to be killed!
Mutation Testing
• Sometimes it is not possible to kill a mutant.
• In this case, the mutant is said to be equivalent to the original program.
• To measure the mutation adequacy of a test set T for a program P, we can use the
mutation score metric (MS):
Mutation Testing
• Mutation Testing is useful in that it can show that certain faults as represented in
the mutants are not likely to be present in the original code since they would
have been revealed by the test cases.
• It also helps the tester to generate hypotheses about the different types of
possible faults in the code and to develop test cases to reveal them.
• There are tools to support developers and testers with producing mutants.
• However, running the tests, analyzing the results, and developing additional tests to kill the
mutants are all time consuming.
• For this reason, mutation testing is usually applied at the unit level.
• However, recent research in an area called interface mutation (the application of mutation
testing to evaluate how well unit interfaces have been tested) has suggested that it can be
applied effectively at the integration test level as well.