White Box Testing in Software Testing
White Box Testing in Software Testing
SE 110
White-box testing
White box testing is a way of testing the external functionality of the code by examining and testing the program code that realizes the external functionality. Synonymous terms: Clear box testing, glass box testing, open box testing. White box testing takes into account the program code, structure and internal design flow.
SE 110 Spring 2012
Static testing
Involves only the source code and not the executables or binaries. Does not involve executing the program on a machine but rather humans going through it or the usage of specialized tools. Some of the properties tested by static testing: Whether the code works according to the functional requirement Whether the code has been written in accordance with the design developed earlier in the project life cycle Whether the code follows all applicable standards Whether the code for any functionality has been missed out Whether the code handles errors properly
SE 110 Spring 2012
Desk checking
Author informally checks the code against the specifications and corrects defects found. No structured method or formalism is required to ensure completeness. No log or checklist is maintained. It relies only on the thoroughness of the author. It may suffice for obvious programming errors but may not be effective for incomplete / misunderstood requirements.
SE 110 Spring 2012
Advantages The programmer knows the code and programming language well and hence is best suited to read the program. Less scheduling and logistics overheads. Reduces delay in defect detection and correction. Disadvantages Person dependent, not scalable or reproducible. Tunnel visioning of developers. Developers prefer writing new code and dont like testing.
SE 110 Spring 2012
Code walkthrough
Group oriented (as against desk checking). Brings in multiple perspectives
A set of people look at the program and raise questions for the author. The author explains the logic of the code and answers the questions. Unanswered questions during walkthrough are answered later by the author.
Fagan Inspection
Group-oriented activity Highly formal and structured Has specific roles Requires thorough preparation
Advantages Thorough, when prepared well Brings in multiple perspectives Has been found to be very effective Disadvantages Logistically difficult Time consuming May not be possible to exhaustively go through the entire code
SE 110 Spring 2012
Structural testing
Done by running the executable on the machine. Entails running the product against some predefined test cases and comparing the results against the expected results. Designing test cases and test data to exercise certain portions of code. Types of structural testing Unit / code functional testing Code coverage testing Code complexity testing
SE 110 Spring 2012
Instrumented code can monitor what parts of code is covered. Can help identify critical portions of code, executed often.
SE 110 Spring 2012
Types of coverage
Statement coverage Path coverage Condition coverage Function coverage
Statement coverage
Statement coverage refers to writing test cases that execute each of the program statements. Typical program constructs constituting program statements:
Sequential instructions. Two-way decision statements (if then else). Multi-way decision statements (switch statements). Loops, like while/do, for, repeat/until, etc. Additional constructs for OO-languages.
Generate test data to make the program enter the sequential block, to make it go through the entire block.
SE 110 Spring 2012
Have test cases to test then part Have test cases to test else part
Switch statement can be reduced to multiple two way if-then-else statements. Thus, there would be multiple test cases to cover all possible cases of switch statement.
SE 110 Spring 2012
while
until
Typically loops fail in boundary conditions. Test cases to achieve statement coverage for statements within a loop should be such that
They skip the loop completely, so that the situation of the termination condition being true before starting the loop is tested. They should exercise the loop between once and the maximum number of times, to check normal operations of the loop. They should try to cover the loop, around the boundary of the loop, i.e. with values just below the boundary, the boundary value and values just above the boundary.
SE 110 Spring 2012
4 A
IT-101
F01-UT-01
4 B
4 A 4 D 4 F
creditHours
grade
4 A 4 B 4 C 4 D 4 F
F01-UT-04
Empty collection
Loop count = 0
creditHours
grade 4 A 4 B 4 C 4 D 4 F
Path coverage
Statement Coverage may not indicate true coverage. Path coverage splits the program into a number of paths, a test can start from the beginning and take any of the paths to its completion. Path coverage = (Total paths exercised/Total number of paths in program)*100.
SE 110 Spring 2012
Some paths:
A B-D-G B-D-H B-C-E-H B-C-F-G
Condition coverage
Further refinement of path coverage. Makes sure each constituent condition in a Boolean expression is covered. Protects against compiler optimizations. Condition coverage = Total conditions exercised / total number of conditions in the program)*100. Condition coverage is much stronger criteria than path coverage which in turn is a stronger criteria than statement coverage.
SE 110 Spring 2012
Function coverage
Finds how many functions are covered by test cases. Higher level of abstraction; hence possible to achieve 100% coverage. More logical than the other types of coverage. Can be derived from RTM. Easy to prioritize as they are based on requirements. Leads more naturally to black box tests. Can also be a natural predecessor to performance testing. Function coverage = (Total functions exercised/Total number of functions in program)*100.
SE 110 Spring 2012
Performance analysis and optimization. Resource usage analysis. Checking of critical sections. Identifying memory leaks. Dynamically generated code (e.g., dynamic generation of URLs and security checking).
SE 110 Spring 2012
Cyclomatic complexity: Intuitive meaning Provides an indication of how many independent paths are there in a program What gives birth to new paths? How can one count the new paths that are born?
Make sure that all edges terminate in some node, adding a node to represent all the statements at the end of the program.
Example #1
Hypothetical diagram with no decision nodes
# of independent paths = 1 # of nodes, N = 2; # of edges, E = 1; Cyclomatic complexity = E N + 2 = 1 # of predicate nodes, P = 0; Cyclomatic complexity = P + 1 = 1
End
Example #2
Hypothetical diagram with one decision node
# of independent paths = 2 # of nodes, N = 4; # of edges, E = 4; Cyclomatic complexity = E N + 2 = 2 # of predicate nodes, P = 1; Cyclomatic complexity = P + 1 = 2
End
Independent paths
An independent path is a path in the flow graph that has not been traversed before in other paths. A set of independent paths that cover all the edges is called a basis set. Find the basis set and write the test cases to execute all the paths in the basis set.
10-20
20-40
>40
Not testable, any amount of money / effort to maintain may not be SE 110 Spring 2012 enough