Unit 2 FSD
Unit 2 FSD
5
CODE REVIEW
Code review for a module is undertaken after the
module successfully compiles.
That is , all the syntax errors have been eliminated
form the module.
Eliminating an error from code involves three main
activities – testing, debugging and then correcting
the errors.
Testing is carried out to detect if the system fails to
work satisfactory for certain types of inputs and
under certain circumstances.
Once a failure is detected, debugging is carried out to
locate the error that is causing the failure.
6
Finally, error correction is carried out to fix the bug.
Types of code review technique
CODE INSPECTION
CODE WALKTHROUGH
7
CODE INSPECTION
During code inspection, the code is examined for the
presence of some common programming errors.
The principal aim of code inspection is to check for
the presence of some common types of errors that
usually creep into code due to programmer
oversights and to check whether coding standards
have been adhered to.
Good software development companies collect
statistics regarding different types of errors
commonly committed by their engineers and
identify the types of errors most frequently
8
committed.
Following is a list of some classical
programming errors which can be checked
during code inspection:
Use of uninitialized variables
Jumps into loops
Non-terminating loops
Incompatible assignments
Array indices out of bounds
Improper storage allocation and deallocation.
Mismatches between actual and formal
parameter in procedure calls. 9
Internal Documentation:
These are provided in the source code itself.
External Documentation:
These are the supporting documents that
usually accompany a software product.
13
INTERNAL DOCUMENTATION
Internal documentation is provided in the source
code itself.
Internal documentation can be provided in the
code in several forms.
The important types of internal documentation are
the following:
Comments embedded in the source code.
Use of meaningful variable names,
Module and function headers.
Code structuring.
Use of enumerated types.
Use of CONSTANT identifiers. 14
EXTERNAL DOCUMENTATION
18
TESTING METHODS
There are two main approaches to design test
cases:
Black-box Approach
20
BLACK-BOX TESTING
In black-box testing, test cases are designed from
an examination of the input/output values only
and no knowledge of design or code is required.
The following are the two main approaches
available to design black-box test cases.
Equivalence Class Partitioning
Boundary Value Analysis
21
EQUIVALENCE CLASS PARTITIONING
In the equivalence class partitioning approach,
domain of input values to the program under
test is partitioned into a set of equivalence
classes.
The partitioning is done such that for every
input data belonging to the same equivalence
class, the program behaves similarly.
Equivalence classes for a program can be
designed by examining the input data and
output data.
22
The following two general guidelines for designing the
equivalence classes.
1. If the input data values to a system can be specified
by a range of values, then one valid and two invalid
equivalence classes need to be defined. For example,
if the equivalence class is the set of integers in the
range 1 to 10, then the invalid equivalence classes
are [-∞,0],[11,+∞].
2. If the input data assumes values from a set of
discrete members of some domain, then one
equivalence class for the valid input values and
another equivalence for the invalid input values
should be defined. For example, if the valid
equivalence classes are {A,B,C}, then the invalid class
23
is U-{A,B,C}, where U is the universe of possible
input values.
Example, for a software that computes the
square root of an input integer that can
assume values in the range of 0 to 5000.
Determine the equivalence class test suite.
26
WHITE-BOX TESTING
White-box testing is an important type of unit
testing.
A large number of white-box testing strategies
exist.
Each testing strategy essentially designs test case
based on analysis of some aspect of source code and
is based on some heuristic.
A white-box testing strategy can either be
coverage-based or fault-based.
Fault-based testing
A fault-based testing strategy targets to detect certain 27
types of faults.
Coverage-based testing
A coverage-based testing strategy attempts to
execute certain elements of a program.
Popular examples of coverage-base testing
strategies are statement coverage, branch
coverage and path coverage-based testing.
28
Statement Coverage:
The statement coverage-based strategy aims to design test cases
so as to execute every statement in a program at least once.
It is obvious that without executing a statement, it is difficult to
determine whether it leads to a failure due to some illegal
memory access, wrong result computation due to improper
arithmetic operation, etc.
Example: Design statement coverage-based test suite for the
following Euclid’s GCD computation program.
int computeGCD(int x,int y)
{
while(x!=y)
{
if(x>y) then
x=x-y;
else
y=y-x;
} 29
}
To design the test cases for the statement
coverage, the conditional expression of the while
statement needs to be made true and the
conditional expression of the if statement needs
to be made both true and false.
By choosing the test set { (x=3, y=3) , (x=4, y=3) ,
(x=3, y=4) } all statements of the program would
be executed at least once.
30
Branch Coverage:
Branch coverage-based testing requires test cases to
be designed so as to make each branch condition in
the program to assume true and false values in turn.
Branch testing is also known as edge testing, since in
this testing scheme, each edge of a program’s control
flow is traversed at least once.
For previous example, the test cases for branch
coverage can be {(x=3, y=3) , (x=3, y=2) , (x=4, y=3) ,
(x=3, y=4) }.
Branch coverage-based testing is a stronger testing
than statement coverage-based testing.
31
Path Coverage:
Path coverage-based testing strategy requires designing
test cases such that all linearly independent paths in the
program are executed at least once.
A linearly independent path can be defined in terms of the
control flow graph(CFG) of a program.
A control flow graph describes how the control flows
through the program.
In order to draw the flow graph of a program, we need to
first number all the statements of a program.
The different numbered statements serve as nodes of the
control flow graph.
There exists an edge from one node to another, if the
execution of the statement representing the first node can
32
Selection:
1. if(a>b)
2. c=3;
3. else c=5;
4. c=c*c;
33
Iteration:
1. while(a>b) {
2. b=b-1;
3. b=b*a;}
4. c=a+b ;
34