SE-Module-4 Testing
SE-Module-4 Testing
Module – 4
2
Coding Phase
§ During coding phase:
§ Every module identified in the design document is
§ Coded &
§ Unit tested
§ Unit testing:
§ Testing of different modules/units of a system
in isolation
3
Unit Testing
5
Coding
§ Objective of coding phase:
6
Coding Standards
§ Good software development organizations require their
programmers to:
§ Adhere to some standard style of coding called coding
standards
§ Some formulate their own coding standards & follow them
rigorously
§ Advantages:
§ Gives an uniform appearance to the codes written by different
engineers
§ Enhances code understandability
§ Encourages good programming practices 7
Coding Standards &
guidelines
8
Example Coding Standards
§ Rules for limiting the use of global variables
§ Rules of thumb:
§ On average there must be at least
§ One comment line for every three source lines
11
Code inspection vs
code walk throughs
§ Objectives
§ To ensure coding standards are followed
§ To detect as many errors as possible before testing
§ Detected errors require less effort for correction at this
stage
§ Much higher effort needed if errors were to be detected
during integration or system testing 12
(1) Code Walk Through
16
What is testing ?
Testing a program:
17
Testing
ü Vary large input data domain makes it impractical to test for each
input value
ü But testing exposes & reduces many defects in the system
ü Increases the users' confidence
ü Testing is very important: Needs most time/effort of all phases
ü As much challenging as other phases & needs creativity
18
Commonly used terms
Ø Test case:
This is the Triplet [I,S,O], where I is the data input to the
system, S is the state of the system, and O is the
expected output of the system
Ø Test suite:
This is the set of all test cases with which a given
software product is to be tested
19
Verification vs Validation
21
Black-box Testing
SQRT O
26
Boundary Value Analysis
1. Statement coverage
2. Branch coverage
3. Condition coverage
4. Path Coverage
5. CFG – Cyclomatic complexity
28
(1) Statement Coverage
29
Example: Design statement coverage-based
test suite for the GCD computation program
31
Example: Design Branch coverage-based
test suite for the GCD computation program
32
(3) Condition Coverage
EX:
• Consider the conditional expression
• ((c1.and.c2).or.c3):
• Each of c1, c2, and c3 are given true and false values
33
(4) Path Coverage
ü Design test cases such that:
ü All linearly independent paths are executed at least
once
ü linearly independent paths are determined from
Control flow graph (CFG) of a program
34
Construction of CFG
36
Linearly independent set of
paths (or basis path set)
An alternative definition:
Ø If a set of paths is linearly independent of each other,
then no path in the set can be obtained through any
linear operations (i.e., additions or subtractions) on
the other paths in the set.
37
McCabe’s Cyclomatic Complexity
Metric
Method3: V(G) = N + 1
Where N is the number of decision and loop statements of a program
38
Example 1: McCabe's Cyclomatic
Complexity
Formulae :
1. V(G) = E – N + 2 (9-7+2=4)
2. V(G) = the number of bounded areas + 1 = 3 + 1 = 4
3. V(G) = number of decision and loop statements + 1 = 3 + 1 = 4
Example 1
while (i<n-1) do :1 2
while (j<n) do :2
if A[i]<A[j] then :3
swap(A[i], A[j]); :4 3
end do; :5
i=i+1; :6
end do; :7 7 4 5
6
Ø Basis path Set (No. of Independent paths)
Ø 1, 7 1
Ø 1, 2, 6, 1, 7
Ø 1, 2, 3, 4, 5, 2, 6, 1, 7 2
Ø 1, 2, 3, 5, 2, 6, 1, 7
7 4 5
6
Example 2: McCabe's
Cyclomatic Complexity
z V(G) = E – N + 2 = 7 – 6 + 2 = 3
z V(G) =No.of bounded area + 1 = 2 + 1 =3
z V(G) = No.of decision and loop statements + 1 = 2+ 1 = 3
41
Example-2
1
9
2
4
3
5 6
7
8
What is V(G)?
Example-3
Steps to carry out path
coverage-based testing
44
Basis Path Testing
• It ensures that product is fault free and is reliable for its intended purpose.
49
UNIT TESTING
50
Driver and stub modules
55
Big-bang approach to
integration testing
57
Bottom-up approach to
integration testing
Advantages:
Ø Several disjoint subsystems can be tested
simultaneously.
Ø The low-level modules get tested thoroughly, since they
are exercised in each integration step.
Disadvantages:
Ø Complexity that occurs when the system is made up of a
large number of small subsystems that are at the same
level.
58
Top-down approach to
integration testing
59
Mixed approach to
integration testing
61
SYSTEM TESTING
62
System Testing
ü There are three main kinds of system testing:
ü Alpha Testing:
ü Performed by the test team within the developing organization
ü Beta Testing
ü Performed by a select group of friendly customers
ü Acceptance Testing
ü Performed by the customer himself to determine whether the
system should be accepted or rejected
63
Regression testing
64
Mutation Testing
§ Stress testing
§ also known as endurance testing
§ If an OS is supposed to support 15
multiprogrammed jobs,
§ the system is stressed by attempting to run 15 or
more jobs simultaneously.
zVerify that:
yall required artefacts for maintenance exist
ythey function properly
Documentation tests
yuser guides,
ymaintenance guides,
ytechnical documents
Documentation tests
81
Brute force method
87
Error Seeding
90