Software Engineering
Software Testing
Chapter-14: Testing
Objectives
— To understand the role of testing in ensuring software quality
—To discuss issues relevant to software testing —To describe the different techniques used for
The Process of Coding, Testing
and Installation
• Coding
– Physical design specifications are turned into
working computer code.
• Testing
– Tests are performed using various strategies.
– Testing can be performed in parallel with
coding.
• Installation
– The current system is replaced by the new
4
Validation & Verification
• Validation
– “Are we building the product right?”
– Ensure software meets customer’s needs
• Verification
– “Are we building the right product?”
6
Why We Need Software Testing?
• Reveal faults/failures/errors • Locate faults/failures/errors • Show system correctness
• Improved confidence that system performs as specified (verification)
• Improved confidence that system performs as desired (validation)
Importance of Testing
• Critical Element of Software Quality Assurance • Well-planned and thorough testing are
important in reducing the high cost of software failure
• Can take up to 40% of development effort
• In systems that require high reliability, testing
8
Who Should Test The Software?
• Developer (individual units)
• Independent test group (ITG)
– removes conflict of interest
User Acceptance Testing
• Actual users test a completed information
system.
• End result is the users’ final acceptance of the
system.
• Alpha testing: use simulated data
• Beta testing: use real data in real user
Test Cases
• Test case: a scenario of transactions,
queries or navigation paths
• Can represent either:
– Typical system use
– Critical system use
– Abnormal system use
• Test cases and results should be thoroughly
Test Cases (cont)
• Test case : unit of testing activity • Test cases have 3 parts
:-– Goal
• Aspect of the system being tested
– Input and system state
• Data provided to the system under stated condition
– Expected behavior
Unit testing
• Unit testing is the process of testing individual
components in isolation.
• It is a defect testing process. • Units may be:
– Individual functions or methods within an object – Object classes with several attributes and methods – Composite components with defined interfaces
Manual Testing Techniques
• Inspection
– A testing technique in which participants examine program code for predictable language-specific errors • Walkthrough
– A peer group review of any product created during
the systems development process; also called a structured walkthrough
• Desk Checking
– A testing technique in which the program code is
White Box Testing
• Derived from knowledge of program’s
structure & implementation
• Structural testing - analyse code & use
knowledge of the structure of a component to derive test data
• Logical paths are tested by providing test
18
White Box Testing
(Continued)• Thorough white box testing would lead to
“100 percent correct programs”
• Exhaustive testing are impractical - too many
tests!
• A limited number of logical paths can be
selected and exercised
• Important data structures can be probed for
White Box Test Cases
• Guarantee that all independent paths have
been exercised at least once
• Exercise all logical decisions on their true and
false sides
• Execute all loops at their boundaries and
within their operational bounds
• Exercise internal data structures to ensure
Decision Coverage
• Decision (Branch) Coverage Method
• Causes every decision (if, switch, while, etc.) in the
program to be made both ways (or every possible way for switch)
• System: Design a test case to exercise each decision in
the program each way (true / false)
• Completion criterion: A test case for each side of each
decision
Condition Coverage
• Condition Coverage Method
• Like decision coverage, but causes every condition expression to be
exercised both ways (true / false)
• A condition is any true / false subexpression in a decision
– Example:
• if (( x == 1 || y > 2) && z < 3)
• Requires separate condition coverage tests for each of:
• x == 1 true / false • y > 2 true / false • z < 3 true / false
• More effective than simple decision coverage since exercises the
Loop Coverage Method
• Most programs do their real work in do, while and for loops
• This method makes tests to exercise each loop in the program in four different states – execute body zero times (do not enter loop)
– execute body once (i.e., do not repeat) – execute body twice (i.e., repeat once) – execute body many times
• Usually used as an enhancement of a statement, block, decision or condition coverage
method
• System: Devise test cases to exercise each loop with zero, one, two and many
repetitions
Loop Coverage Method
if there is an upper bound, n, on the number of times the loop body can be executed, then the following cases should also be applied.
•Design a test in which the loop body is executed exactly n-1
times.
•Design a test in which the loop body is executed
exactly n times.
•Try to design a test causing the loop body to be executed
Loop Coverage Method
Apply the following guidelines to ensure that each loop is tested at its boundaries (that is, with both minimal and maximal numbers of iterations of the loop body) while using a number of tests that is only linear in the number of loops:
•Conduct the ``simple loop tests'' for the innermost loop (which is a simple loop), while keeping the number of iterations of the outer loops at their minimal
nonzero values.
•Work outward, conducting tests (as described above) for each loop, while holding the number of iterations of outer loops at the minimal nonzero values possible (that is, the minimal values that can be used when the inner loop body is to be executed the desired number of times), and holding the number of
Execution Paths
• An execution path is a sequence of executed
statements starting at the entry to the unit (usually the first statement) and ending at the exit from the unit (usually the last statement)
• Two paths are independent if there is at least one
statement on one path which is not executed on the other
• Path analysis (also know as cyclomatic complexity
28
Flow Graph Notation
Converting Code to Graph
if expression1 then
statement2
else
statement3 end if
statement4
switch expr1 case 1:
statement2 case 2:
statm3 case 3: statm4 end switch statm5 (a) (b) do statement1
CODE FLOWCHART GRAPH
T expr1 F ?
statm4
statm2 statm3
2
1 expr1 3 ? statm5 statm3 statm2 statm4 n1 n2 n3 n4 n1 n2 n4 n5 n3 statm1 n1
For a strongly connected graph: Create a virtual edge
Cyclomatic Complexity
• Region, R= 6
Number of Nodes = 13 Number of edges = 17
Cyclomatic Complexity
• Cyclomatic Complexity for a flow graph is computed in one of three ways: • The numbers of regions of the flow graph correspond to the Cyclomatic
complexity.
• Cyclomatic complexity, V(G), for a flow graph G is defined as
V(G) = E – N + 2
where E is the number of flow graph edges and N is the number of flow graph nodes.
• Cyclomatic complexity, V(G), for a graph flow G is also defined as
Cyclomatic Complexity
Cyclomatic Complexity, V( C) : V( C ) = R = 6;
Or
V(C) = Predicate Nodes + 1 =5+1 =6
Or
Execution Paths Analysis
• To achieve 100% basis path coverage, you
need to define your basis set. The cyclomatic complexity of this method is four (one plus the number of decisions), so you need to
define four linearly independent paths. To do this, you pick an arbitrary first path as a
Execution Paths Analysis
• Path 1: Any path will do for your baseline, so pick true for the decisions'
outcomes (represented as TTT). This is the first path in your basis set.
Path 2: To find the next basis path, flip the first decision (only) in your baseline, giving you FTT for your desired decision outcomes.
Path 3: You flip the second decision in your baseline path, giving you TFT for your third basis path. In this case, the first baseline decision remains fixed with the true outcome.
Path 4: Finally, you flip the third decision in your baseline path, giving you TTF for your fourth basis path. In this case, the first baseline decision
remains fixed with the true outcome.
Path Coverage Testing
• Advantages
– Covers all basic blocks (does all of basic block testing)
– Covers all conditions (does all of decision/condition
testing)
– Does all of both, but with fewer tests!
– Automatable (in practice requires automation)
• Disadvantages
if expression1 then
statement2 end if
do
statement3
while expr4
end do
if expression5 then
statement6 end if
statement7
Solution
n1 n3 n2 n4 n5 n7 n6 e1 e2 e3 e4 e5 e6 e7 e8 e9 e10if expression1 then
statement2 end if
do
statement3
while expr4
end do
if expression5 then
statement6 end if
statement7
Discussion on White Box Testing
• Advantages
– Find errors on code level
– Typically based on a very systematic approach, covering
the complete internal module structure
• Constraints
– Does not find missing or additional functionality – Does not really check the interface
40
Black Box Testing
• Derived from program specification
• Functional testing of a component of a system
• Examine behaviour through inputs & the
corresponding outputs
• Input is properly accepted, output is correctly
produced
Black Box Testing
(Continued)Attempts to find the following errors:
• Incorrect or missing functions • Interface errors
• Errors in data structures or external database
access
• Performance errors
Types
Types of Black Box Testing
There are many types of Black Box Testing but following are the prominent ones
-Functional testing - This black box testing type is related to functional requirements of a system; it is done by software testers.
Non-functional testing - This type of black box testing is not related to testing of a specific functionality , but non-functional requirements such as performance, scalability, usability.
Equivalence Partitioning
• Divide input domain into classes of data
• Based on an evaluation of equivalence classes for an input condition
• Guidelines to define equivalence classes
– Range input : One valid and two invalid equivalence – Specific value : One valid and two invalid equivalence
44
Example – Data for Automated Banking Application
The use can access the bank using his personal computer, provide a six digit password, and follow with a series of typed commands that trigger various banking function. During the log on sequence the software supplied for the banking application accepts data in the form:
area code – blank or 3 digit numbers
prefix – 3 digit numbers, nor beginning with 0 or 1 suffix – 4 digit numbers
password – 6 digits alphanumeric strings commands – “check”, “deposit”, “bill pay” etc
Input condition
area code : Input condition : Boolean – area code may or may not present Input condition : Range – 200 – 999 with specific exception prefix : Input condition : Range – specified value > 200 with no 0 digits suffix : Input condition : Value – 4 digit length
password : Input condition : Boolean – password may or may not present Input condition : Value – six character string
46
Boundary Value Analysis
• Complement equivalence partitioning • Test both sides of each boundary
• Look at output boundaries for test cases
• Test min, min-1, max, max+1, typical values • Example : 1 <= x <=100
48
Comparison Testing
• Used only in situations in which the reliability of
software is absolutely critical (e.g., human-rated systems)
– Separate software engineering teams develop
independent versions of an application using the same specification
– Each version can be tested with the same test data to
ensure that all provide identical output
– Then all versions are executed in parallel with
Orthogonal Array Testing
• Used when the number of input parameters
is small and the values that each of the parameters may take are clearly bounded
X Y
Z
X Y
50
Discussion on Black Box Testing
• Advantages
– Find missing functionality
– Independent from code size and functionality – Find some coding errors
• Constraints
Black box testing techniques
Black box testing strategy:
Following are the prominent test strategy amongst the many used in Black box Testing
Equivalence Class Testing: It is used to minimize the number of
possible test cases to an optimum level while maintains reasonable test coverage.
Boundary Value Testing: Boundary value testing is focused on the values at boundaries. This technique determines whether a certain
range of values are acceptable by the system or not. It is very useful in reducing the number of test cases. It is mostly suitable for the systems where input is within certain ranges.
Summary
We have learned
• To understand the role of testing in ensuring software quality
References
1- These slides are designed to accompany Software
Engineering: A Practitioner’s Approach, 7/e (McGraw-Hill 2009). Slides copyright 2009 by Roger Pressman.
2- http://www.cs.unc.edu/~stotts/145/cocomo7.gif
3-Software Engineering” by Ian Somerville, Addison-Wesley, 2009