Unit 2
Unit level Testing
Contents
• Overview of white box testing
• Control flow testing
• Process of generating test input data : Example
• Various coverage criterias
• Dataflow testing
• Data flow anomalies
• Data flow graph
• Data flow terminologies
Overview of white box testing
• The testers require knowledge of how the software is implemented, the tester is concentrating
on how the software does it. For example, a structural technique may be concerned with
exercising loops in the software.
• WHITE BOX TESTING is testing of a software solution's internal structure, design, and
coding. In this type of testing, the code is visible to the tester.
• It focuses primarily on verifying the flow of inputs and outputs through the application,
improving design and usability, strengthening security.
• Performs to check/verify
• Internal security holes
• Broken or poorly structured paths in the coding processes
• The flow of specific inputs through the code
• Expected output
• The functionality of conditional loops
• Testing of each statement, object, and function on an individual basis
Example
Printme (int a, int b)
{
int result = a+ b;
If (result> 0)
Print ("Positive", result)
Else
Print ("Negative", result)
}
“The goal of White Box testing is to verify
all the decision branches, loops, statements
in the code.”
Advantages of White Box Testing
• Code optimization by finding hidden
errors.
• White box tests cases can be easily
automated.
• Testing is more thorough as all code
paths are usually covered.
• Testing can start early in SDLC even if
GUI is not available.
Disadvantages of White Box Testing
• White box testing can be quite complex and expensive.
• The white box testing by developers is not detailed can lead to
production errors.
• White box testing requires professional resources, with a
detailed understanding of programming and implementation.
• White-box testing is time-consuming, bigger programming
applications take the time to test fully.
Control Flow testing: Process of Generating Test
Input Data
Statement Coverage
• This technique requires every possible
statement in the code to be tested at least
once during the testing process.
• Statement coverage =( number of statement
executed/total number of statements )
1.Printme (int a, int b){
2. int result = a+ b;
3. If (result> 0)
4. Print ("Positive", result)
5. Else
6. Print ("Negative", result)
7.}
Scenario 1:
A= 5 B= 6;
The statements marked in red colour are those which are
executed as per the scenario
Number of executed statements = 5,
Total number of statements = 7
Statement Coverage: 5/7 = 71%
What is covered by Statement Coverage?
 Unused Statements
 Dead Code
 Unused Branches
 Missing Statements
Branch Coverage vs Decision coverage
• This technique requires every possible branch in
the code to be tested at least once during the
testing process.
• Branch coverage=(number of branches
executed/total number of branches)
What is covered by Branch Coverage?
 Allows you to validate-all the branches in the code
 Helps you to ensure that no branched lead to any abnormality
of the program's operation
 Branch coverage method removes issues which happen
because of statement coverage testing
 Allows you to find those areas which are not tested by other
testing methods
 It allows you to find a quantitative measure of code coverage
 Branch coverage ignores branches inside the Boolean
expressions
TestValueofX(int x)
{
if (x>9)
print x;
print (x+6);
}
Test
Case
Value of
X
Output Branch
Coverage
1 8 14 67%
2 10 10 ,16 100%
• Reports true or false outcomes of each Boolean expression. In
this coverage, expressions can sometimes get complicated.
Therefore, it is very hard to achieve 100% coverage.
Test case 1
• Number of executed decision = 1,
• Total number of decisions = 2
Test case 2
• Number of executed decision = 1,
• Total number of decisions = 2
TestValueofX(int x)
{
if (x>9)
print x;
else
print (x+6);
}
Test
Case
Value of
X
Output Decision
Coverage
1 8 14 50%
2 10 10 50%
Branch Coverage vs Decision coverage
Data Flow Testing
Data Flow Anomalies
• Defined and Then Defined Again
• Example: int x=10;
int x=12; // In same source code
• Undefined but Referenced
• Example: x=10; // In source code is undefined
• Defined but Not Referenced
• Example: int x; // In source code , x is defined but not referenced.
Data Flow Graph Example
Data Flow Graph Example
Data Flow Terminologies and C-use(ti) variable
all-c-uses criterion with respect to variable ti
Paths should be 1-2-3-4-5-6-3-7-8-10, 1-2-3-4-5-6-3-7-9-10, 1-2-3-4-6-3-7-8-10, and 1-2-3-4-6-3-7-9-10.
!!..Thank You..!!

Unit 2 Unit level testing.ppt

  • 1.
  • 2.
    Contents • Overview ofwhite box testing • Control flow testing • Process of generating test input data : Example • Various coverage criterias • Dataflow testing • Data flow anomalies • Data flow graph • Data flow terminologies
  • 3.
    Overview of whitebox testing • The testers require knowledge of how the software is implemented, the tester is concentrating on how the software does it. For example, a structural technique may be concerned with exercising loops in the software. • WHITE BOX TESTING is testing of a software solution's internal structure, design, and coding. In this type of testing, the code is visible to the tester. • It focuses primarily on verifying the flow of inputs and outputs through the application, improving design and usability, strengthening security. • Performs to check/verify • Internal security holes • Broken or poorly structured paths in the coding processes • The flow of specific inputs through the code • Expected output • The functionality of conditional loops • Testing of each statement, object, and function on an individual basis
  • 4.
    Example Printme (int a,int b) { int result = a+ b; If (result> 0) Print ("Positive", result) Else Print ("Negative", result) } “The goal of White Box testing is to verify all the decision branches, loops, statements in the code.” Advantages of White Box Testing • Code optimization by finding hidden errors. • White box tests cases can be easily automated. • Testing is more thorough as all code paths are usually covered. • Testing can start early in SDLC even if GUI is not available. Disadvantages of White Box Testing • White box testing can be quite complex and expensive. • The white box testing by developers is not detailed can lead to production errors. • White box testing requires professional resources, with a detailed understanding of programming and implementation. • White-box testing is time-consuming, bigger programming applications take the time to test fully.
  • 5.
    Control Flow testing:Process of Generating Test Input Data
  • 6.
    Statement Coverage • Thistechnique requires every possible statement in the code to be tested at least once during the testing process. • Statement coverage =( number of statement executed/total number of statements ) 1.Printme (int a, int b){ 2. int result = a+ b; 3. If (result> 0) 4. Print ("Positive", result) 5. Else 6. Print ("Negative", result) 7.} Scenario 1: A= 5 B= 6; The statements marked in red colour are those which are executed as per the scenario Number of executed statements = 5, Total number of statements = 7 Statement Coverage: 5/7 = 71% What is covered by Statement Coverage?  Unused Statements  Dead Code  Unused Branches  Missing Statements
  • 7.
    Branch Coverage vsDecision coverage • This technique requires every possible branch in the code to be tested at least once during the testing process. • Branch coverage=(number of branches executed/total number of branches) What is covered by Branch Coverage?  Allows you to validate-all the branches in the code  Helps you to ensure that no branched lead to any abnormality of the program's operation  Branch coverage method removes issues which happen because of statement coverage testing  Allows you to find those areas which are not tested by other testing methods  It allows you to find a quantitative measure of code coverage  Branch coverage ignores branches inside the Boolean expressions TestValueofX(int x) { if (x>9) print x; print (x+6); } Test Case Value of X Output Branch Coverage 1 8 14 67% 2 10 10 ,16 100%
  • 8.
    • Reports trueor false outcomes of each Boolean expression. In this coverage, expressions can sometimes get complicated. Therefore, it is very hard to achieve 100% coverage. Test case 1 • Number of executed decision = 1, • Total number of decisions = 2 Test case 2 • Number of executed decision = 1, • Total number of decisions = 2 TestValueofX(int x) { if (x>9) print x; else print (x+6); } Test Case Value of X Output Decision Coverage 1 8 14 50% 2 10 10 50% Branch Coverage vs Decision coverage
  • 9.
  • 10.
    Data Flow Anomalies •Defined and Then Defined Again • Example: int x=10; int x=12; // In same source code • Undefined but Referenced • Example: x=10; // In source code is undefined • Defined but Not Referenced • Example: int x; // In source code , x is defined but not referenced.
  • 11.
  • 12.
  • 13.
    Data Flow Terminologiesand C-use(ti) variable all-c-uses criterion with respect to variable ti Paths should be 1-2-3-4-5-6-3-7-8-10, 1-2-3-4-5-6-3-7-9-10, 1-2-3-4-6-3-7-8-10, and 1-2-3-4-6-3-7-9-10.
  • 14.