0% found this document useful (0 votes)
15 views

Structural Testing

The document discusses structural testing techniques like control flow testing and data flow testing. Control flow testing aims to execute all statements and branches in a program while data flow testing focuses on variable definitions and uses.

Uploaded by

kulwantchahar123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Structural Testing

The document discusses structural testing techniques like control flow testing and data flow testing. Control flow testing aims to execute all statements and branches in a program while data flow testing focuses on variable definitions and uses.

Uploaded by

kulwantchahar123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Structural Testing

Structural Testing
• It is considered more technical than functional testing. It attempts to design test case from the
source code , not from specifications .
• It also gives insight in to the source code which may be used as an essential knowledge for the
design of test cases.
• Structural testing techniques are also known as white box testing techniques due to consideration
of internal structure and other implementation details of the program.

Structural Testing

Control Flow Testing Data Flow Testing


Control Flow Testing
• This technique is very popular due to its simplicity and effectiveness. We identify paths of
the program and write test cases to execute those paths. As we all know, path is a
sequence of statements that begins at an entry and ends at an exit.
• Every path covers a portion of the program. We define ‘coverage’ as a ‘percentage of
source code that has been tested with respect to the total source code available for
testing’. We may like to achieve a reasonable level of coverage using control flow testing.
• The most reasonable level may be to test every statement of a program at least once
before the completion of testing. Hence, we may write test cases that ensure the execution
of every statement.
• If we do so, we have some satisfaction about reasonable level of coverage. If we stop
testing without achieving this level (every statement execution), we do unacceptable and
intolerable activity which may lead to dangerous results in future.
Control Flow Testing(Continued)
• Statement Coverage:- We want to execute every statement of the program in order to achieve 100%
statement coverage.
• 1. void main() Total Path:- 1. 1-7,10,13-15
• 2. { 2. 1-7,10-15
• 3. int a,b,c,x=0,y=0; 3. 1-10,13-15
• 4. clrscr(); 4. 1-15
• 5. printf("Enter three numbers:");
• 6. scanf("%d %d %d",&a,&b,&c);
• 7. if((a>b)&&(a>c)){
• 8. x=a*a+b*b; The cyclomatic Complexity of graph:-
• 9. } V(G)=e-n+2
• 10. if(b>c){ V(G)=16-15+2=3
• 11. y=a*a-b*b; Independiente Paths(green) =3
• 12. }
• 13. printf("x= %d y= %d",x,y);
• 14. getch();
• 15. }
Control Flow Testing(Continued)
• Branch Coverage:-We want to test every branch of the program. Hence, we wish to
test every ‘True’ and ‘False’ condition of the program. If we select a = 9, b = 8, c = 7, we
achieve 100% statement coverage and the path followed is given as (all true conditions):
Path = 1–15
• We also want to select all false conditions with the following inputs:
• a = 7, b = 8, c = 9, the path followed is Path = 1–7, 10, 13–15
• These two test cases out of four are sufficient to guarantee 100% branch coverage. The
branch coverage does not guarantee 100% path coverage but it does guarantee 100%
statement coverage.
Control Flow Testing(Continued)
• Condition Coverage:- Condition coverage is better than branch coverage because we
want to test every condition at least once. However, branch coverage can be achieved
without testing every condition.
• The statement number 7 has two conditions (a>b) and (a>c). There are four possibilities namely:
(i) Both are true
(ii) First is true, second is false
(iii) First is false, second is true
(iv) Both are false
• Hence, we should write test cases for every true and false condition. Selected inputs may be given
as:
• (i) a = 9, b = 8, c = 7 (first possibility when both are true) (ii) a = 9, b = 8, c = 10 (second
possibility – first is true, second is false) (iii) a = 7, b = 8, c = 9 (third and fourth possibilities- first
is false, statement number 7 isfalse)
Control Flow Testing(Continued)
• Path Coverage:- In this coverage criteria, we want to test every path of the program. There are too
many paths in any program due to loops and feedback connections. we may be confident about the
correctness of the program. If it is unachievable, at least all independent paths should be executed.

• Q. Try Consider the program for the determination of the division of a student. Derive test cases so that 100%
path coverage is achieved.(Program and program Graph is given in Software Testing by Yogesh Singh P.No-
130)
Data Flow Testing

• It is based on variables, their usage and their definition in the program. The main points of
concern are:
(i) Statements where variables receive values (definition).
(ii) Statements where these values are used (referenced).

• 1. # include < stdio.h>


• 2. void main ()
• 3. {
• 4. int a, b, c;
• 5. a = b + c;
• 6. printf (“%d”, a);
• 7. }
Data Flow Testing(continued)
1.Define/Reference Anomalies:- Some of the define / reference anomalies are given as:
• (i) A variable is defined but never used / referenced.
• (ii) A variable is used but never defined.
• (iii) A variable is defined twice before it is used.
• (iv) A variable is used before even first-definition.
2.Definitions:- A program is first converted into a program graph. As we all know, every statement of a program is replaced by
a node and flow of control by an edge to prepare a program graph.
• 2.1. Defining Node:- A node of a program graph is a defining node for a variable , if and only if, the value of the variable v is
defined in the statement corresponding to that node. It is represented as DEF (v , n) where is the variable and n is the node
corresponding to the statement in which is defined.
• 2.2. Usage Node:- A node of a program graph is a usage node for a variable , if and only if, the value of the variable is used in
the statement corresponding to that node. It is represented as USE (v , n), where ‘v ’ is the variable and ‘n’ in the node
corresponding to the statement in which ‘ v’ is used.
• 2.3. Definition use Path:- A definition use path (denoted as du-path) for a variable ‘v ’ is a path between two nodes ‘m’ and ‘n’
where ‘m’ is the initial node in the path but the defining node for variable ‘ ’ (denoted as DEF ( v, m)) and ‘n’ is the final node in
the path but usage node for variable ‘ v’ (denoted as USE (v , n)).
• 2.4. Definition clear path:-A definition clear path (denoted as dc-path) for a variable ‘v ’ is a definition use path with initial and
final nodes DEF (v , m) and USE (v , n) such that no other node in the path is a defining node of variable ‘v ’.
Data Flow Testing(continued)
• Identification of du and dc paths:- The various steps for the identification of du and dc paths are given as:
• (i) Draw the program graph of the program.
• (ii) Find all variables of the program and prepare a table for define / use status of all variables using the following format:

S.No. Variable Defined at node Used at node

• (iii) Generate all du-paths from define/use variable table of step (iii) using the following format:

S.NO. Variable Du-path(begin,end)

• (iv) Identify those du-paths which are not dc-paths.


Data Flow Testing(continued)
• Testing Strategies Using du-paths:- We want to generate test cases which trace
every definition to each of its use and every use is traced to each of its definition. Some of
the testing strategies are given as:
1. Test all du-paths:- All du-paths generated for all variables are tested. This is the
strongest data flow testing strategy covering all possible du-paths.
2. Test all uses:- Find at least one path from every definition of every variable to every use
of that variable which can be reached by that definition. For every use of a variable, there is
a path from the definition of that variable to the use of that variable.
3. Test all definitions :- Find paths from every definition of every variable to at least one
use of that variable; we may choose any strategy for testing.
• 1. void main()

Data Flow Testing(continued) Example


• 2. {
• 3. float A,B,C;
• 4. clrscr();
• 5. printf("Enter number 1:\n");
• 6. scanf("%f", &A);
• 7. printf("Enter number 2:\n");
• 8. scanf("%f", &B);
• 9. printf("Enter number 3:\n");
• 10. scanf("%f", &C);
• 11. if(A>B) {
• 12. if(A>C) {
• 13. printf("The largest number is: %f\n",A);
• 14. }
• 15. else {
• 16. printf("The largest number is: %f\n",C);
• 17. }
• 18. }
• 19. else {
• 20. if(C>B) {
• 21. printf("The largest number is: %f\n",C);
• 22. }
• 23. else {
• 24. printf("The largest number is: %f\n",B);
• 25. }
• 26. }
• 27. getch();
• 28. }
Data Flow Testing(continued) Example
• Generation of test cases:- Define /use nodes for all these variables are given below:
S. No. Variable Define at Used at node
node
1 A 6 11,12,13
2 B 8 11,20,24
3 C 10 12,16.20,21
• The du-path with beginning node and end node are given as:-
Variable Du-path(Begin ,end)

A 6,11
6,12
6,13
B 8,11
8,20
8,24
C 10,12
10,16
10,20
10,21
Data Flow Testing(continued) Example

You might also like