You are on page 1of 11

Lecture#26

STRUCTURE-BASED (WHITE-BOX) TECHNIQUES


Purpose of Structure based Techniques

• Structure-based test techniques are used to explore system or


component structures at several levels
• At the component level, the structures of interest will be program
structures such as decisions
• at the integration level we may be interested in exploring the way
components interact with other components
• at the system level we may be interested in how users will interact
with a menu structure
Structure based Techniques Explained
• Instead of exercising a component or system to see if it functions
correctly white-box tests focus on ensuring that particular elements
of the structure itself are correctly exercised
• For example, we can use structural testing techniques to ensure that
each statement in the code of a component is executed at least once
• Basis for test case generation at component level: Code
• What should a tester capable of: Read and Analyze the code
• Structure-based testing at the component level are mostly done by
specialist tools, but a knowledge of the techniques is still valuable
OVERALL PROGRAM STRUCTURE
• Code can be of two types, executable and non-executable.
• Executable code instructs the computer to take some action; non-executable
code is used to prepare the computer to do it calculations but it does not
involve any actions
• For example, reserving space to store a calculation (this is called a declaration
statement) involves no actions

• Lets assume executable


and non executable
Statements???
Programming Structures
REPEAT UNTIL Loop
Flow Chart for Visual Representation of Code
Code Coverage Techniques
Statement Coverage:
In this the  test case  is executed in such a way that every statement  of the code  is  executed
at least once.

Branch/Decision Coverage:

• Test coverage criteria requires enough test cases such that each condition in a decision takes
on all possible outcomes at least once, and each point of entry to a program or subroutine is
invoked at least once.  
• That is, every branch (decision) taken each way, true and false. It helps in validating all the
branches in the code making sure that no branch leads to abnormal behavior of the application
Example (Code Coverage)
Rules for SC, BC and PC
• Statement Coverage (SC):

• To calculate Statement  Coverage, find out the shortest number of paths following 
which all the nodes will be covered. Here by traversing through path 1A-2C-3D-E-4G-5H
all  the nodes are covered. So by traveling through only one path all the nodes 12345
are covered,  so the Statement coverage in this case is 1
• Branch Coverage (BC):

• To calculate Branch Coverage, find out the minimum number of paths which will
ensure covering of all the edges. In this case there is no single path which will ensure
coverage of all the edges at one go. By following paths 1A-2C-3D-E-4G-5H, maximum
numbers of edges (A, C, D, E, G and H) are covered but edges B and F are left.
• To covers these edges we can follow 1A-2B-E-4F. By the combining the above two paths
we can ensure of traveling through all the paths. Hence Branch Coverage is 2. The aim
is to cover all possible true/false decisions
Test cases
• Number of test cases?
• For the above example Statement Coverage=1, Branch coverage=2 .

You might also like