Software Engineering Lectures
Software Engineering Lectures
Lecture - 1
Testing
Levels of Testing
Integration Testing
2
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
What is Testing?
Once source code has been generated, software must be tested to
uncover as many errors as possible before delivery to your customer
Your goal is to design a series of test cases that have a high likelihood
of finding errors.
Testing
The aim of Testing is to detect all the errors in a program or system.
As the input data domain of most of the programs is very large, it is
not practical to test the program exhaustively with respect to all values
that the input domain can assume.
A careful testing can expose most of the errors and hence reduce
defects.
4
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Basic terminologies?
Error
- is a mistake committed by development team during any of the
development phases.
- also referred as a fault, a bug or a defect.
Failure
- manifestation of an error.
- an error may not necessary lead to a failure.
Test case
- presented as triplet [I, S, O] where I : input, S: state, O: expected
output.
Test suite
- Set of all test cases with which system has to be tested.
5
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Testing Activities
3. Debugging
- identify the statements that are in error.
- failure symptoms are analyzed to locate the errors.
4. Error correction
6
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
When test cases are designed on random data input, many of the test
cases do not contribute to the significance of the test suite. Because,
they do not identify any additional error which is not already detected.
if (x > y) max = x;
else max = x;
A minimal test suite is a carefully designed set of test cases such that
each test case helps detect deferent error. This is in contrast to testing
using some random input values.
7
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Levels of Testing
Unit testing
Integration testing
System testing
After testing all the units individually, the units are slowly integrated
and tested after each step of integration (integration testing).
8
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Unit Testing
Unit testing is undertaken after a module has been coded and
reviewed.
Before carrying out unit testing, the unit test cases have been
designed and test environment for the unit under test has to be
developed.
9
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Unit Testing
Stub
•A stub is a dummy procedure that has same I/O parameters as the
given procedure, but has a highly simplified behaviour.
•For example, a stub procedure may produce the expected behaviour
using a simple look up mechanism.
Driver
•A driver module should contain the non-local data structures accessed
by module under test.
•It should also have the code to call the different functions of the
module under test with appropriate parameter values for testing.
10
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Black-box Testing
11
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
13
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Example: Design the equivalence test classes for a program that reads
two integer pairs (m1, c1) and (m2, c2) defining straight lines of the
form y = mx + c. The program computes the intersection point of the
two straight lines and displays point of intersections.
14
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Example: Design the equivalence test classes for a function that reads
a character string of size less than five characters and display whether
it is a palindrome.
15
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
16
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
BVA Example
The boundary value-based test suite is: {0, -1, 5000, 5001}.
17
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
18
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
19
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
20
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
21
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
White-Box Testing
Fault-based Testing
-attempts to execute (or cover) certain elements of program.
-examples are statement coverage, branch coverage, and path
coverage base testing.
Coverage-based Testing
-targets to detect certain types of faults. These faults that a test
strategy focuses on constitutes the fault model of the strategy.
- example is mutation testing.
22
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
23
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
A is stronger testing
strategy B
A and B are
complementary
testing strategy
24
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Statement Coverage
25
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Branch Coverage
26
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
(ii)To show that statement coverage does not ensure branch coverage,
it would be sufficient to give an example of a test suite that achieves
statement coverage, but does not cover at least one branch.
Consider the following code, and the test suite {5}.
if( x > 2) x += 1;
27
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Condition Coverage
For example, in the conditional expression ((c1 .and. c2) .or. c3), the
components c1, c2 and c3 are each assume both true and false.
28
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Path Coverage
requires designing test cases such that all linearly independent path
(basis paths) in the program are executed at least once.
29
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
Drawing CFG
Arrows on the Flow-Graph indicate edges
Each circle one or more procedural statements
Area bounded by edges and nodes are considered as regions.
30
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Compiler Design
31
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata
Control Flow Graph (CFG)
Control Flow Graph (CFG) for an example program
A path through a program is any node and edge sequence from start
node to end node of the control flow graph of a program.
A program can have more than one terminal nodes when it contains
multiple exit or return statements.
Writing test cases for exercising all paths is impractical since there
are infinite number of paths.
Though the McCabe’s metric does not directly identify the linearly
independent paths, but it provides us with a practical way of
determining approximately how many paths to look for.
McCabe’s Cyclomatic
Method 1
Given a control flow graph G, the cyclomatic complexity V(G) can be
computed as:
V(G) = E – N + 2
where, N is the number of nodes and E is the number of edges.
Method 2
V(G) = Total number of non-overlapping bounded areas + 1
Method 3
Step 4: Repeat
Test using randomly designed set of test cases.
Perform dynamic analysis to check the path coverage achieved.
until at least 90% path coverage is achieved.
Other uses of McCabe’s cyclomatic complexity metric
X ϵ DEF(S)
and
X ϵ USES(S)
And the definition of X in the statement S is live at statement S1.
If there exists at least one test case in the test suite for which a
mutated program yield an incorrect result, then the mutant is said to
be dead, since the error introduced by the mutation operator
successfully been detected by test suite.
If a mutant remains alive even after all the test cases have been
exhausted, the test suite is enhanced to kill the mutant.
Mutation Testing
Advantage:
it can be automated to a great change.
Disadvantage:
it is computationally very expensive, since a large number of possible
mutants can be generated.
Typological error
Integration errors
The unit test is white-box oriented, and the step can be conducted in
parallel for multiple components.
Unit Test Considerations
Top-down approach
Bottom-up approach
4. Drivers are removed and clusters are combined moving upward in the
program structure.
Bottom-up integration
Components are combined to form clusters 1, 2, and 3. Each of the clusters is tested
using a driver (shown as a dashed block). Components in clusters 1 and 2 are subordinate
to Ma. Drivers D1 and D2 are removed and the clusters are interfaced directly to Ma.
Similarly, driver D3 for cluster 3 is removed prior to integration with module Mb. Both Ma
and Mb will ultimately be integrated with component Mc, and so forth.
Top-down integration testing
It starts with the root module. After the top-level skeleton has been
tested, the modules that are immediately lower layer of the skeleton
are combined with it and tested. (Modules are integrated by moving
downwards).
Disadvantage of top-down
integration testing approach is that in
the absence of lower-level routines,
many times it may become difficult to
exercise the top-level routines in
desired manner since the lower level
routines perform several lower low-
level functions such as the input /
output operations.
The integration process is performed in a series of five steps:
1. The main control module is used as a test driver and stubs are substituted
for all components directly subordinate to the main control module.
4. On completion of each set of tests, another stub is replaced with the real
component.
• Tests that focus on the software components that have been changed.
Smoke Testing
2. A series of tests is designed to expose errors that will keep the build
from properly performing its function. The intent should be to uncover
“show stopper” errors that have the highest likelihood of throwing the
software project behind schedule.
3. The build is integrated with other builds and the entire product (in its
current form) is smoke tested daily. The integration approach may be
top down or bottom up.
Smoke testing provides a number of benefits when it is applied
on complex, time critical software engineering projects:
• Integration risk is minimized. Because smoke tests are conducted
daily, incompatibilities and other show-stopper errors are uncovered
early, thereby reducing the likelihood of serious schedule impact when
errors are uncovered.
69
Arup Kr. Chattopadhyay, Department of IT, IEM, Kolkata