Lecture 07
Lecture 07
White Box
by
Dr. Rizwan
White Box Testing
White box testing is also know as Glass Testing or Open box
testing is detailed examination of internal structure and logic of
code.
This examination is demonstrated through test cases creation
by looking at the code to detect any potential failure scenarios.
Disadvantages of White Box Testing
Objectiv The primary goal is to identify The main objective is to detect The purpose is to present and
e defects, improve quality, and defects, ensure compliance with explain the artifact, gather
gather feedback on the artifact standards, and improve quality feedback, and clarify its content
Approac Reviewers examine the artifact Involves a defined set of roles The author guides the
h individually before the review and responsibilities, with specific participants through the artifact,
meeting, providing their insights entry and exit criteria. The highlighting its key aspects,
and raising questions or process includes a thorough explaining the rationale behind
concerns during the meeting. examination of the artifact decisions, and soliciting input or
The focus is on the content, against predefined checklists or suggestions. The focus is on
correctness, and adherence to criteria to identify issues comprehension, understanding,
standards systematically and knowledge sharing
Interacti Discussions and feedback Follow a more formal process, Participants actively engage in
on sharing are crucial during the with a designated moderator discussions, ask questions,
review meeting to capture leading the session and provide feedback, and offer
8
different perspectives and foster participants adhering to suggestions
collaboration inspection guidelines
Structural or White-box Testing (WBT)
9
Coding Standards and Guidelines
There are 3 reasons for adherence to a standard or
guidelines:
Reliability It's been shown that code written to a specific
standard or guideline is more reliable and secure than code that
isn't.
Readability/ Maintainability Code that follows set standards
and guidelines is easier to read, understand and maintain.
Portability Code often has to run on different hardware or be
compiled with different compilers. If it follows a set of
standards, it will likely be easier - or even completely painless -
to move it to a different platform.
Generic Code Review Checklist
Data Reference Errors
• bugs caused by using a variable, constant, array, string, or
record that hasn’t been properly declared or initialized
Computation Errors
• computational or calculation errors. The calculations don’ t
result in the expected result.
Comparison Errors
• <, >, =, not =, true, false. Comparison and decision errors are very
susceptible to boundary condition problems.
Source Code Checklist
Is the design implemented completely and correctly?
Are there missing or extraneous functions?
Is each loop executed the correct number of times?
Will each loop terminate?
Will the program terminate?
Are all possible loop fall-throughs correct?
Are all CASE statements evaluated as expected?
Is there any unreachable code?
Are there any off-by-one iteration errors?
Source Code Checklist
Are there any dangling ELSE clauses?
Is pointer addressing used correctly?
Are priority rules and brackets in arithmetic expression
evaluation used as required to achieve desired results?
Are boundary conditions considered? (e.g., null or negative
values, adding to an empty list, etc.)
Are pointer parameters used as values and vice-versa?
Interfaces
Is the number of input parameters equal to then number of
arguments?
Do parameter and argument attributes match?
Do the units of parameters and arguments match?
Are any input-only arguments altered?
Are global variable definitions consistent across modules?
Are any constants passed as arguments?
Are any functions called and never returned from?
Are returned VOID values used?
Are all interfaces correctly used as defined in the Software
Design Description?
Data and Storage
Are data mode definitions correctly used?
Are data and storage areas initialized before use, correct fields accessed
and/or updated?
Is data scope correctly established and used?
If identifiers with identical names exist at different procedure call
levels, are they used correctly according to their local and global scope?
Are all pointers based on correct storage attributes?
Is the correct level of indirection used?
Are any string limits exceeded?
Are all variables EXPLICITLY declared?
Are all arrays, strings, and pointers initialized correctly?
Are all subscripts within bounds?
Are there any non-integer subscripts?
Maintainability and Testability
Is the code understandable (i.e., choice of variable names, use of
comments, etc.)
Is there a module header?
Is there sufficient and accurate commentary to allow the reader to
understand the code?
Does the formatting and indenting style add to the readability of the
code?
Are coding conventions followed?
Is tricky or obscure logic used?
Is the code structured to allow for easier debugging and testing?
Is the code structured so that it could be easily extended for new
functions?
Are there any unnecessary restrictions to extensions due to code
structure?
Error Handling
Are all probable error conditions handled?
Are error messages and return codes used?
Are they meaningful and accurate?
Are the default branches is CASE statements handled correctly?
Does the code allow for recovery from error conditions?
Is range checking done where appropriate to isolate the source
of an error?
Complexity Warning
Numbered statements:
Represent nodes of the flow graph
Defined at Used at
Variable
node node
x 1 2, 3
y 1 2, 4
a 3, 4 5
White Box Testing
White box testing utilizes the logical flow through a program to propose test
cases.
Logical flow means the way in which certain parts of a program may be
executed as we run the program. Logical flow of a program can be
represented by a control flow graph.
Most common white box testing methods are:
Statement Coverage
Decision/Branch Coverage
Condition Coverage
Path Coverage
Structural or White-box Testing (WBT)
Verifies the correct implementation of internal units (statements, data
structures, blocks etc.) and relations among them
Connection between execution behavior and internal units needs to be made
in WBT
Various software tools are used for this purpose
The simplest form of WBT is Statement Coverage Testing.
29
White Box Testing Techniques
Coverage/Code coverage
Code Coverage = (Number of lines of code executed)/(Total
Number of lines of code in a system component) * 100
Statement Coverage/Block coverage
The number of statements that have been successfully executed in the
program source code
Decision Coverage/Branch Coverage
The number of decision control structures that have been successfully
executed in the program source code
Function coverage
The number of functions that are called and executed at least once in
the source code
Statement Coverage
int abs(int x ) {
if ( x ≥ 0 )
x = 0 - x;
return x;
}
Structural or White-box Testing (WBT)
Statement Coverage Testing
If A = 3, B = 9
33
Structural or White-box Testing (WBT)
Statement Coverage Testing
If A = -3, B = -9
34
Branch Coverage
return TRUE;
}
Inputs Actual Output
Test Cases x
T1 -5
T2 5
Branch Coverage
/* finding the maximum of two integers x and y */
int Max_check(int x, y, max) {
If (x>y) max = x;
else max = y;
}
Inputs Actual Output
Test Cases x y
T1 3 2
T2 2 4
Condition Coverage
20. else {
21. cout<<" Invalid entry for maximum "<<endl;
22. }
23. if (number1 < number2 && number1 < number3) {
24. cout<<"Number 01 is minimum…"<<endl;
25. }
26. else if (number2 < number1 && number2 < number3) {
27. cout<<"Number 02 is minimum…"<<endl;
28. }
29. else if (number3 < number1 && number3 < number2) {
30. cout<<"Number 03 is minimum…"<<endl;
31. }
32. else {
33. cout<<" Invalid entry for minimum "<<endl;
34. }
35. return 0;
36. }
How to Design Test Case Through White Box
1 2 5 3 Number 2 is Max
Number 1 is Mini
How to Design Test Case Through White Box
2 9 5 2 Num 1 is Max
Num 3 is Mini
How to Design Test Case Through White Box
3 3 7 6 Number 2 is Max
Number 1 is Mini
How to Design Test Case Through White Box
3 3 8 2 9 Number 3 is Max
Number 2 is Mini
How to Design Test Case Through White Box
1) main ( ) {
2) int num student, marks, subject, total ;
3) float average ;
4) num_student = 1;
5) while (num_student < = 40) {
6) total = 0 ;
7) subject = 1;
8) while (subject < = 5) {
9) Scanf ("Enter marks : % d”, & marks);
10) total = total + marks ;
11) subject ++;
12) }
13) average = total/5 ;
14) if (average > = 50)
15) printf ("Pass... Average marks = % f", average);
16) else
17) print ("FAIL ... Average marks are % f”, average) ;
18) num_student ++;
19) }
20) printf ("end of program") ;
21) }
ECP