Need:: Looking at The Structure of The Code Ensure
Need:: Looking at The Structure of The Code Ensure
Need:: Looking at The Structure of The Code Ensure
UNIT-III
Dynamic Testing II: White-Box Testing: need, Logic coverage criteria, Basis path testing, Graph
matrices, Loop testing, data flow testing, mutation testing
Example:
scanf(“%d%d”,&x,&y);
while(x!=y)
{
if(x>y)
x=x-y;
else
y=y-x;
}
printf(“x=%d y=%d”,x,y);
Statement Coverage:
It is assumed that if all the statements of the module are executed once, every bug will be
notified. If we want to cover every statement in the above code, then the following test cases must
be designed:
Test case 1: x = y = n, where n is any number
Test case 2: x = n, y = n’, where n and n’ are different numbers.
Test case 3: x>y
Test case 4: x<y
Flow Graph Notations fro Different Programming Constructs: Flow graph is also known as
Decision to Decision (D&D) graph.
Path Testing Terminology:
Path: A path through a program is a sequence of instructions or statements that starts at an entry,
junction, or decision and ends at another or possibly the same junction, decision or exit.
Segment: Path consists of segments. The smallest segment is a link, that is, a single process that
lies between two nodes.
Path Segment: A path segment is a succession of consecutive links that belongs to some path.
Length of a Path: The length of a path is measured by the number of links in it and not by the
number of instructions or statements executed along the path.
Independent Path: An independent path is any path through the graph that introduces at least one
new set of processing statements or new conditions.
Cyclomatic Complexity:
--It provides a quantitative measure of the logical complexity of a program
--Defines the number of independent paths in the basis set
--Provides an upper bound for the number of tests that must be conducted to ensure all statements
have been executed at least once
--Can be computed three ways
-->The number of regions
-->V(G) = E – N + 2, E is the number of edges and N is the number of nodes in graph G
-->V(G) = P + 1, where P is the number of predicate nodes in the flow graph G
Example:
Flow graph for above example is:
-->V(G) = e – n + 2
= 10 – 8 +2
= 4
-->V(G) = Number of predicate nodes + 1
= 3 (Nodes B,C and F) + 1
= 4
Graph Matrices:
Flow graph is an effective aid in path testing. However, path tracing with the use of flow
graphs may be a cubersome and time consuming activity. Graph Matric ,a data structure is the
solution which can assist in developing a tool for automation of path tracing.
Graph Matrix:
A Graph Matrix is a square matrix whose size is equal to the number of nodes on the flow
graph. Each row and column corresponds to an identified node, and matrix entries correspond to
connections between nodes.
Connection Matrix:
If we add link weights to each cell entry, then graph matrix can be used as a powerfull tool in
testing. The links between two nodes are assigned a link weight which becomes the entry in the cell
of matrix. The link weight provides information about control flow.
Example:
Loop Testing:
If loops are not tested properly, bugs can go undetected. Loop testing can be done effectively while
performing unit testing by the developer. Different kinds of loops available for testing are:
Simple loops:
The following test cases should be considered for simple loops while testing them:
--> Check whether the loop control variable is negative.
--> Write one test case that executes the statements inside the loop.
--> Write test cases for a typical number of iterations through the loop.
--> Write test cases for checking the boundary values of maximum and minimum number of
iterations defined (say min and max) in the loop. It means we should test for the min, min+1, min-1,
max-1, max and max+1 number of iterations through the loop.
Nested Loops:
If we have nested loops in the program it is difficult to test. If we adopt the approach of simple tests
to test the nested loops, then the number of possible test cases grow geometrically. Thus the strategy
is to start with the innermost loops while holding outer loops to their minimum values. Continue
this outward in this manner until all loops have been covered
Concatenated loops:
Two loops are concatenated if it is possible to reach one after exiting the other while still on a path
from entry to exit. If two loops are not on the same path, then they are not coancatenated.
Data flow Testing:
Data Flow Testing is a white-box testing technique that can be used to detect improper use
of data values due to coding errors. Errors may be unintentionally introduced in a program by
programmers. For instance:
--A programmer might use a variable without defining it.
--He may define a vraible but not initialize it.
Static Flow Testing: With static analysis, the source code is analysed without executing it. Let us
consider an example of an application given below:
Example:
main()
{
int a=10,b=10,c;
c=a+b;
printf(“Value=%d”,c);
}
For Variable 'a':
Pattern Line Number Explanation
-d 3 Normal Case: Allowed
du 3-4 Normal Case: Allowed
uk 4 Normal Case: Allowed
Example:
Flow graph: Data Flow Graph
Mutation Testing
Mutation testing is the process of mutating some segment of code(putting some error in the code)
and then testing this mutated code with some test data. If the test data is able to detect the mutations
in the code. Mutation testing helps a user create test data by interacting with the user to iteratively
strengthen the quality of test data. During mutation testing, faults are introduced into a program by
creating many versions of the program, each of which contains one fault. Test data are used to
execute these faulty programs with the goal of causing each faulty program to fail.
Faulty programs are called mutants of the original program and a mutant is said to be killed when a
test case causes it to fail. When this happens, the mutant is considered dead
Primary Mutants:
When the mutants are single they are called as primary nutants. Mutation operators are
dependent on programming languages.
Example: if(a>b)
x = x+y;
else
x=x-y;
printf(“%d”,x);
Secondary Mutants:
Example: if(a<b)
c=a;
M1: if(a<=b-1)
c=a;
M3: if(a==b)
c=a+1;
Static Testing
Features of Software Testing:
--Static testing techniques do not demonstrate that the software is operational or one function of
software is working;
--They check the software product at each SDLC stage for conformance with the required
specifications or standards. Requirements, design specifications, test plans, source code, user’s
manuals, maintenance procedures are some of the items that can be statically tested.
--Another advantage in static testing is that a bug is found at its exact location whereas a bug found
in dynamic testing provides no indication to the exact source code location.
Inspections:
-->Inspection process is an in-process manual examination of an item to detect bugs.
-->Inspection process is carried out by a group of peers. The group of peers first inspects the
product at individual level. After this, they discuss potential defects of the product observed in a
formal meeting.
-->It is a very formal process to verify a software product. The documents which can be inspected
are SRS, SDD, code and test plan.
-->Inspection process involves the interaction of the following elements:
a) Inspection steps b) Roles for participants c)Item being inspected
Inspection Team:
-->Author / Owner / Producer: A programmeror designer responsible for producing the program
or document.
-->Inspector: A peer member of the team, i.e he is not a manager or supervisor. He is not directly
related to the product under supervision and may be concerned with some other products.
-->Moderator: A team member who manages the whole inspection process. He schedules, leads,
and controls the inspection session.
-->Recorder: One who records all the results of the inspection meeting.
Inspection Process:
Inspection Meeting: Once all the initial preparation is complete, the actual inspection meeting can
start. The inspection meeitng starts with the author of the inspected item who has created it. The
author first discusses every issue raised by different members in the compiled log file. After the
discussion, all the members arrive at a consensus whether the issues pointed out are in fact errors
and if they are errors, should they be admitted by the author.
Rework: The summary list of the bugs that arise during the inspection meeting needs to be
reworked by the author. The auhor fixes all these bugs and reports back to the moderator.
Follow-Up: It is the responsibility of the moderator to check that all the bugs found in the last
meeting have been resolved. The document is then approved for release.
-->Bug Reduction: Accorrding to the report that through the inspection process in IBM, the
number of bugs per thousand lines of code has been reduced by two thirds.
-->Bug Prevention: Based on the experience of previous inspections, analysis can be made for
future inspections or projects, therby preventing the bugs which have appeared earlier.
-->Productivity: Since all phases of SDLC may be inspected without waiting for code development
and its execution, the cost of finding bugs decreases and increases productivity.
-->Real-time Feedback to Software Engineers: Developers find out the type of mistakes they
make and what is the error density. Since they get this feedback in the early stage of the
development, they may improve their capability.
-->Reduction in Development Resource: Inspections reduce the effort required for dynamic
testing and any rework during design and code, thereby causing an overall net reduction in the
development resource.
-->Quality Improvement: The direct consequence of static testing also results in the improvement
of quality of the final product.
-->Project Management
-->Checking Coupling and Cohesion
-->Learning through Inspection
-->Process Improvement
Reading Techniques:
A reading technique can be defined as a series of steps or procedures whose purpose is to
guide an inspector to accquire a deep understanding of the inspected software product. Thus reading
technique can be regarded as a mechanism for the individual inspector to detect defects in the
inspected product. The various reading techniques are:
Ad-hoc Method: The word ad-hoc only refers to the fact that no technical support on how to detect
defects in a software artifact is given them. In this case, defect detection fully depends on the skills,
knowledge, and experience of an inspector.
Checklists: A checklist is a list of items that focus the inspectors attention on specific topics, such
as common defects or organizational rules, while reviewing a software document.
Scenario – Based Reading: Different methods developed based on scenario based reading are:
-->Perspective based Reading: Software item should be inspected from the perspective of different
stakeholders Inspectors of an inspection team have to check software quality as well as the software
quality factors of a software artifact from different perspectives.
-->Usage based Reading: This method given is applied in design inspections. Design
documentation is inspected based on use cases, which are documented in requirements
specification.
-->Abstraction driven Reading: This method is designed for code inspections. In this method, an
inspector reads a sequence of statements in the code and abstracts the functions these statements
compute.
-->Task driven Reading: This method is also for code inspections . In this method, the inspector has
to create a data dictionary, a complete description of the logic and a cross-reference between the
code and the specifications.
->Function-point based Scenarios: This is based on scenarios for defect detection in requirements
documents [103]. The scenarios, designed around function-points are known as the Function Point
Scenarios. A Function Point Scenario consists of questions and directs the focus of an inspector to a
specific function-point item within the inspected requirements document.
Structured Walkthroughs:
-->It is a less formal and less rigorous technique as compared to inspection. The very common term
used in the literature for static testing is Inspection but it is for very formal process. If you want to
go for a less formal having no bars of organized meeting, then walkthroughs are a good option.
-->A review is similar to an inspection or walkthrough, except that the review team also includes
management. Therefore, it is considered a higher-level technique than inspection or walkthrough.
-->A technical review team is generally comprised of management-level representatives of the User
and Project Management. Review agendas should focus less on technical issues and more on
oversight than an inspection.
Technical Review:
--A review is similar to an inspection or walkthrough, except that the review team also includes
management. Therefore, it is considered a higher-level technique than inspection or walkthrough.
--A technical review team is generally comprised of management-level representatives of the User
and Project Management. Review agendas should focus less on technical issues and more on
oversight than an inspection.