You are on page 1of 722

Foundations of Software Testing 2E

Part I

Chapter 1 Chapter 2

Part II

Chapter 3 Chapter 4 Chapter 5 Chapter 6

Part III

Chapter 7 Chapter 8

Part IV

Chapter 9 Chapter 10 Chapter 11

Updated: July 21, 2013
Foundations of Software Testing 2E

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

ADITYA P. MATHUR

Contents
Author: Aditya P. Mathur

1

Chapter 1:

Updated: July 17, 2013

Foundations of Software Testing 2E

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Preliminaries: Software Testing

Contents
Author: Aditya P. Mathur

2

Learning Objectives
Errors, Testing, debugging, test process, CFG, correctness, reliability,

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

n 

oracles.

n 

Finite state machines

n 

Testing techniques

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

3

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

1.1 Humans, errors and testing

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

4

Errors
Errors are a part of our daily life.

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Humans make errors in their thoughts, actions, and in the products that
might result from their

actions.

Errors occur wherever humans are involved in taking actions and making
decisions.

These fundamental facts of human existence
make testing an essential activity.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

5

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Errors: Examples

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

6

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Error, faults, failures

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

7

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

1.2 Software Quality

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

8

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Software quality

Static quality attributes: structured, maintainable, testable code as well as
the availability of correct and complete documentation.

Dynamic quality attributes: software reliability, correctness,
completeness, consistency, usability, and performance

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

9

Software quality (contd.)

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Completeness refers to the availability of all features listed in the requirements,
or in the user manual. An incomplete software is one that does not fully
implement all features required.

Consistency refers to adherence to a common set of conventions and
assumptions. For example, all buttons in the user interface might follow a
common color coding convention. An example of inconsistency would be when
a database application displays the date of birth of a person in the database.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

10

Software quality (contd.)
Usability refers to the ease with which an application can be used. This is an
Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

area in itself and there exist techniques for usability testing. Psychology plays
an important role in the design of techniques for usability testing.

Performance refers to the time the application takes to perform a requested
task. It is considered as a non-functional requirement. It is specified in terms
such as ``This task must be performed at the rate of X units of activity in one
second on a machine running at speed Y, having Z gigabytes of memory."

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

11

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

12

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

1.3 Requirements, behavior, and correctness

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Requirements, behavior, correctness

Requirements leading to two different programs:

Requirement 1: It is required to write a

program that inputs two integers and outputs the maximum of these.

Requirement 2: It is required to write a

program that inputs a sequence of integers and outputs the sorted version of
this sequence.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

13

Requirements: Incompleteness

of max when the input integers are 13 and 19 can be easily determined to be 19.

Suppose now that the tester wants to know if the two integers are to be input to the
program on one line followed by a carriage return, or on two separate lines with a
carriage return typed in after each number. The requirement as stated above fails to
provide an answer to this question.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

14

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Suppose that program max is developed to satisfy Requirement 1. The expected output

Contents Foundations of Software Testing 2E Author: Aditya P. The behavior of sort program.Requirement 2 is ambiguous. Mathur 15 Copyright © 2013 Dorling Kindersley (India) Pvt. will depend on the decision taken by the programmer while writing sort. Ltd Requirements: Ambiguity . written to satisfy this requirement. It is not clear whether the input sequence is to sorted in ascending or in descending order.

of P.The set of all possible inputs to a program P is known as the input domain or input space. Using Requirement 2 it is not possible to find the input domain for the sort program.767. Using Requirement 1 above we find the input domain of max to be the set of all pairs of integers where each element in the pair integers is in the range -32.768 till 32. Mathur 16 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Input domain (Input space) . Contents Foundations of Software Testing 2E Author: Aditya P.

the sequence is terminated with a period. and ``D'' otherwise. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd It is required to write a program that inputs a sequence of integers and outputs the integers in this sequence sorted in either ascending or descending order. Mathur 17 . While providing input to the program. the request character is input first followed by the sequence of integers to be sorted.Input domain (Continued) Modified Requirement 2: Copyright © 2013 Dorling Kindersley (India) Pvt. The order of the output sequence is determined by an input request character which should be ``A'' when an ascending sequence is desired.

Mathur 18 Copyright © 2013 Dorling Kindersley (India) Pvt. The first element of the pair is a character.Based on the above modified requirement. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Input domain (Continued) . the input domain for sort is a set of pairs. The second element of the pair is a sequence of zero or more integers ending with a period.

Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 19 . but fails to answer the question ``What if the user types a different character ?’’ When using sort it is certainly possible for the user to type a character other than ``A'' and ``D''. Any character other than ``A'’ and ``D'' is considered as invalid input to sort.Valid/Invalid Inputs The modified requirement for sort mentions that the Copyright © 2013 Dorling Kindersley (India) Pvt. The requirement for sort does not specify what action it should take when an invalid input is encountered. Ltd request characters can be ``A'' and ``D''.

Mathur 20 . Ltd 1.Copyright © 2013 Dorling Kindersley (India) Pvt.4 Correctness versus reliability Contents Foundations of Software Testing 2E Author: Aditya P.

Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Though correctness of a program is desirable.Correctness never the objective of testing. correctness is established via mathematical proofs of programs. In most cases that are encountered in practice. To establish correctness via testing would imply testing a program on all elements in the input domain. it is almost . Thus. this is impossible to accomplish. Mathur 21 Copyright © 2013 Dorling Kindersley (India) Pvt.

Contents Foundations of Software Testing 2E Author: Aditya P. testing attempts to find if there are any errors in it. and the error removal processes together increase our confidence in the correct functioning of the program under test. Mathur 22 . Testing. completeness of testing does not necessarily demonstrate that a program is error free. debugging. Ltd While correctness attempts to establish that the program is error free.Correctness and Testing Copyright © 2013 Dorling Kindersley (India) Pvt. Thus.

Ltd Software reliability: two definitions Software reliability [ANSI/IEEE Std 729-1983]: is the probability of failure free operation of software over a given time interval and under given conditions. Contents Foundations of Software Testing 2E Author: Aditya P. Software reliability is the probability of failure free operation of software in its intended environment. Mathur 23 .Copyright © 2013 Dorling Kindersley (India) Pvt.

Contents Foundations of Software Testing 2E Author: Aditya P. Consider a sort program which. Mathur 24 . allows any one of two types of input sequences.Operational profile Copyright © 2013 Dorling Kindersley (India) Pvt. on any given execution. Sample operational profiles for sort follow. Ltd An operational profile is a numerical description of how a program is used.

Mathur 25 . Ltd Operational profile Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd Operational profile Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 26 .

Mathur 27 . Ltd 1.5 Testing and debugging Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

is known as debugging. Contents Foundations of Software Testing 2E Author: Aditya P. the process used to determine the cause of this error and to remove it. Mathur 28 Copyright © 2013 Dorling Kindersley (India) Pvt.Testing is the process of determining if a program has any errors. Ltd Testing and debugging . When testing reveals an error.

Ltd A test/debug cycle Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 29 .

Contents Foundations of Software Testing 2E Author: Aditya P. . one with ``A'' and the other with ``D'' as request characters.Test plan Example: The sort program is to be tested to meet the requirements given earlier. •  Execute sort on at least two input sequences. the following needs to be done. Ltd A test cycle is often guided by a test plan. Mathur 30 Copyright © 2013 Dorling Kindersley (India) Pvt. Specifically.

•  Execute the program on an empty input sequence. •  Test the program for robustness against erroneous inputs such as ``R'' Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 31 . Contents Foundations of Software Testing 2E Author: Aditya P.) typed in as the request character. Ltd Test plan (contd. •  All failures of the test program should be recorded in a suitable file using the Company Failure Report Form.

Mathur 32 . The test data is a set of values.Test case/data A test case is a pair consisting of test data to be input to the program and the Copyright © 2013 Dorling Kindersley (India) Pvt. A test set is a collection of zero or more test cases. one for each input variable. Ltd expected output. Sample test case for sort: Test data: <''A'’ 12 -29 32 > Expected output: -29 12 32 Contents Foundations of Software Testing 2E Author: Aditya P.

A state diagram specifies program states and how the program changes its state on an input sequence. Ltd Program behavior Can be specified in several ways: plain natural language. formal mathematical specification. a state diagram. inputs. Mathur 33 .Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. etc.

Ltd Consider a menu driven application. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 34 .Program behavior: Example Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 35 .) Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Program behavior: Example (contd.Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd In the first step one observes the behavior.Behavior: observation and analysis Copyright © 2013 Dorling Kindersley (India) Pvt. In the second step one analyzes the observed behavior to check if it is correct or not. Both these steps could be quite complex for large commercial programs. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 36 . The entity that performs the task of checking the correctness of the observed behavior is known as an oracle.

Ltd Oracle: Example Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 37 .Copyright © 2013 Dorling Kindersley (India) Pvt.

Oracle: Programs Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Oracles can also be programs designed to check the behavior of other programs. For example. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 38 . one might use a matrix multiplication program to check if a matrix inversion program has produced the correct output. the matrix inversion program inverts a given matrix A and generates B as the output matrix. In this case.

such as the one to check a matrix multiplication program or a sort program.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Oracle: Construction Construction of automated oracles. In general. the construction of automated oracles is a complex undertaking. Mathur 39 . Contents Foundations of Software Testing 2E Author: Aditya P. requires the determination of inputoutput relationship.

Mathur 40 . Ltd Oracle construction: Example Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

program verification is often avoided. Program verification and testing are best considered as complementary techniques. Ltd Testing and verification . Mathur 41 Copyright © 2013 Dorling Kindersley (India) Pvt. In practice. Contents Foundations of Software Testing 2E Author: Aditya P.Program verification aims at proving the correctness of programs by showing that it contains no errors. and the focus is on testing. This is very different from testing that aims at uncovering errors in a program.

there might be an incorrect assumption on the input conditions.Testing and verification (contd. Mathur 42 Copyright © 2013 Dorling Kindersley (India) Pvt.) despite the success of a set of tests. Ltd Testing is not a perfect technique in that a program might contain errors . Verification promises to verify that a program is free from errors. Verified and published programs have been shown to be incorrect. However. Contents Foundations of Software Testing 2E Author: Aditya P. and so on. incorrect assumptions might be made regarding the components that interface with the program. the person/tool who verified a program might have made a mistake in the verification process.

Copyright © 2013 Dorling Kindersley (India) Pvt. Test generation strategies Contents Foundations of Software Testing 2E Author: Aditya P.10. Mathur 43 . Ltd 1.

Test generation Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. The tests are generated using a mix of formal and informal methods either directly from the requirements document serving as the source. In the most informal of test methods. requirements serve as a source for the development of formal models. Mathur 44 . the process is a bit more formal. Ltd Any form of test generation uses a source document. In several commercial environments. the source document resides in the mind of the tester who generates tests based on a knowledge of the requirements. In more advanced test processes.

Timed automata. and Larch. Z. etc. Ltd Model based: require that a subset of the requirements be modeled using a formal notation (usually graphical). Specification based: require that a subset of the requirements be modeled using a formal mathematical notation. Mathur 45 . Contents Foundations of Software Testing 2E Author: Aditya P.Test generation strategies Copyright © 2013 Dorling Kindersley (India) Pvt. Petri net. Models: Finite State Machines. Code based: generate tests directly from the code. Examples: B.

Ltd Test generation strategies (Summary) Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 46 .Copyright © 2013 Dorling Kindersley (India) Pvt.

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 1.13 Types of software testing Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 47 .

C2: Lifecycle phase in which testing takes place C3: Goal of a specific testing activity C4: Characteristics of the artifact under test Contents Foundations of Software Testing 2E Author: Aditya P.Types of testing Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 48 . Ltd One possible classification is based on the following four classifiers: C1: Source of test generation.

Ltd C1: Source of test generation Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 49 .Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 50 . Ltd C2: Lifecycle phase Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd C3: Goal of specific testing activity Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 51 .

Mathur 52 . Ltd C4: Artifact under test Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd Summary We have dealt with some of the most basic concepts in software testing. Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 53 . Exercises at the end of Chapter 1 are to help you sharpen your understanding.

Ltd Chapter 2: Preliminaries: Mathematical Updated: July 12.Copyright © 2013 Dorling Kindersley (India) Pvt. 2013 Foundations of Software Testing 2E Contents Author: Aditya P. Mathur 54 .

Copyright © 2013 Dorling Kindersley (India) Pvt.1 Predicates and Boolean expressions Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 2. Mathur 55 .

pp 133-157. and Vouk.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Where do predicates arise? Predicates arise from requirements in a variety of applications. Here is an example from Paradkar.” V 4. “Specification based testing using cause-effect graphs. A boiler needs to be to be shut down when the following conditions hold: Contents Foundations of Software Testing 2E Author: Aditya P. 1997. Mathur 56 . Annals of Software Engineering. Tai.

  The water level in the boiler is below X lbs.Boiler shutdown conditions 2. (a) . (c) 4. We combine these five conditions to form a compound condition (predicate) for boiler shutdown.  Steam meter has failed. Ltd 1. Contents Foundations of Software Testing 2E Author: Aditya P.  The water level in the boiler is above Y lbs.  A water pump has failed. (d) Boiler in degraded mode when either is true.  A pump monitor has failed. Mathur 57 Copyright © 2013 Dorling Kindersley (India) Pvt. (e) The boiler is to be shut down when a or b is true or the boiler is in degraded mode and the steam meter fails. 5. (b) 3.

we obtain the following Boolean expression E that when true must force a boiler shutdown: E=a+b+(c+d)e where the + sign indicates “OR” and a multiplication indicates “AND.Boiler shutdown conditions Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Denoting the five conditions above as a through e. Mathur 58 .” The goal of predicate-based test generation is to generate tests from a predicate p that guarantee the detection of any error that belongs to a class of errors in the coding of p.

” This statement consists of a condition part and an action part. Mathur 59 Copyright © 2013 Dorling Kindersley (India) Pvt. also known as a Boolean expression.Another example For example. The following predicate represents the condition part of the statement. pr: (printer_status=ON) ∧ (printer_tray!= empty) Contents Foundations of Software Testing 2E Author: Aditya P. . consider the requirement ``if the printer is ON and has paper then send document to printer. Ltd A condition is represented formally as a predicate.

Mathur 60 Copyright © 2013 Dorling Kindersley (India) Pvt. if condition then action is a typical format of many functional requirements. Ltd Test generation from predicates . The conditions from which tests are generated might arise from requirements or might be embedded in the program to be tested. Contents Foundations of Software Testing 2E Author: Aditya P. Conditions guard actions.We will now examine two techniques. named BOR and BRO for generating tests that are guaranteed to detect certain faults in the coding of conditions. For example.

Mathur 61 . AND.g. Simple predicate: A Boolean variable or a relational expression. ≤. Ltd = and == are equivalent. (e. a+b<c) e1 and e2 are expressions whose values can be compared using relop. =. Boolean operators (bop): {!.∨. XOR}. (gender==“female”∧age>65) Contents Foundations of Software Testing 2E Author: Aditya P. ≠. xor} also known as {not. Relational expression: e1 relop e2.} Copyright © 2013 Dorling Kindersley (India) Pvt. OR. ≥. >.∧.Predicates Relational operators (relop): {<. (x<0) Compound predicate: Join one or more simple predicates using bop.

Mathur 62 Copyright © 2013 Dorling Kindersley (India) Pvt..Boolean expression: one or more Boolean variables joined by bop. Ltd Boolean expressions . Negation is also denoted by placing a bar over a Boolean expression such as in (a ∧ b) We also write ab for a∧b and a+b for a∨b when there is no confusion. b.g. e. and c are also known as literals. in (a∧b∨!c) Contents Foundations of Software Testing 2E Author: Aditya P. Singular Boolean expression: When each literal appears only once. (a∧b∨!c) a.

g.) Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 63 .g.g. (p q) +(rs) + (a c)..: (p+q)(r+s)(a+c) Any Boolean expression in DNF can be converted to an equivalent CNF and vice versa. e. Ltd Disjunctive normal form (DNF): Sum of product terms: e.Boolean expressions (contd. CNF: (p+!r)(p+s)(q+!r)(q+s) is equivalent to DNF: (pq+!rs) Contents Foundations of Software Testing 2E Author: Aditya P. Conjunctive normal form (CNF): Product of sums: e.

Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 64 Copyright © 2013 Dorling Kindersley (India) Pvt.Mutually singular: Boolean expressions e1 and e2 are mutually singular when they do not share any literal.. e2. Ltd Boolean expressions (contd. If expression E contains components e1.) .. then ei is considered singular only if it is non-singular and mutually singular with the remaining elements of E.

Mathur 65 .Abstract syntax tree (AST) for: (a+b)<c ∧!p. Copyright © 2013 Dorling Kindersley (India) Pvt. < (a+b) ! c p Leaf nodes Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Boolean expressions: Syntax tree representation Root node (AND-node) Notice that internal nodes are labeled by ∧ Boolean and relational operators Root node: OR-node is labeled as ∨.

Mathur 66 . Ltd 2.2 Program representation: Control flow graphs Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 67 Copyright © 2013 Dorling Kindersley (India) Pvt.A basic block in program P is a sequence of consecutive statements with a single entry and a single exit point. a block has unique entry and exit points. Ltd Program representation: Basic blocks . There is no possibility of exit or a halt at any point inside the basic block except at its exit point. Thus. Control always enters a basic block at its entry point and exits from its exit point. The entry and exit points of a basic block coincide when the block contains only one statement. Contents Foundations of Software Testing 2E Author: Aditya P.

Basic blocks: Example Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 68 . Ltd Example: Computing x raised to y Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd Basic blocks Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 69 .) Copyright © 2013 Dorling Kindersley (India) Pvt.Basic blocks: Example (contd.

Mathur 70 Copyright © 2013 Dorling Kindersley (India) Pvt. We often write G= (N. E) to denote a flow graph G with nodes given by N and edges by E. j) in E connects two nodes ni and nj in N. An edge (i. Ltd Control Flow Graph (CFG) . Contents Foundations of Software Testing 2E Author: Aditya P.A control flow graph (or flow graph) G is defined as a finite set N of nodes and a finite set E of edges.

An edge (i. each basic block becomes a node and edges are used to . j) connecting basic blocks bi and bj implies that control can go from block bi to block bj.Control Flow Graph (CFG) indicate the flow of control between blocks. Mathur 71 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Blocks and nodes are labeled such that block bi corresponds to node ni. We also assume that there is a node labeled Start in N that has no incoming edge. that has no outgoing edge. and another node labeled End. also in N. Ltd In a flow graph of a program.

End)} Contents Foundations of Software Testing 2E Author: Aditya P. (2. 6). 5. (3. 2. 3). (9. (1. 5).Copyright © 2013 Dorling Kindersley (India) Pvt. 8. (4. 7). 2). Ltd CFG Example N={Start. (6. Mathur 72 . 7. (7. (5. 9). 4). (1.4). (7.1). 1. 6. 4. End} E={(Start. 5). (5. 3. 9. 8).

9. (4. 1. (5. 4). (1. N={Start. (9. Mathur 73 . 3). 7.4).CFG Example Copyright © 2013 Dorling Kindersley (India) Pvt. 9).1). (1. End)} Contents Foundations of Software Testing 2E Author: Aditya P. (5. (6. (7. (3. 4. 8). 7). 8. Ltd Same CFG with statements removed. 2. (2. 5). 5. 5). (7. 2). End} E={(Start. 6). 3. 6.

} Contents Foundations of Software Testing 2E Author: Aditya P. nq. nq) and ei+1 = (nr. E). Ltd Consider a flow graph G= (N. Mathur 74 . … e_k) . ns) then nq = nr. Given that np. k>0.Paths Copyright © 2013 Dorling Kindersley (India) Pvt. and 0< i<k. and ns are nodes belonging to N. if ei = (np. (e_1. nr. e_2. A sequence of k edges. denotes a path of length k through the flow graph if the following sequence condition holds.

2. Contents Foundations of Software Testing 2E Author: Aditya P. 5. 9. (1. End) p2= (Start. (4. End)) Bold edges: complete path. 4. 1. 1). 1. End) Specified unambiguously using edges: p1= ( (Start. 5. 7. (5. 6. 6. Ltd Two feasible and complete paths: p1= ( Start. (5. Mathur 75 . 9.Paths: sample paths through the exponentiation flow graph Copyright © 2013 Dorling Kindersley (India) Pvt. (7. 3. Dashed edges: subpath. 2). (2. 7. 7). 6). 4). 5. (6. 4. 5). 9). (9. 5. 5).

7. Ltd A path p through a flow graph for program P is considered feasible if there exists at least one test case which when input to P causes p to be traversed. 7. 9. 9. 5. 1. Mathur 76 . 4. 5. 6. 2. 5. 1. 3. 4. . End) Contents Foundations of Software Testing 2E Author: Aditya P. End) p2= (Start. 8. p1= ( Start.Paths: infeasible Copyright © 2013 Dorling Kindersley (India) Pvt. 1.

A program with no . Ltd There can be many distinct paths through a program. Mathur 77 Copyright © 2013 Dorling Kindersley (India) Pvt. conditions can have a multiplicative effect on the number of paths. Contents Foundations of Software Testing 2E Author: Aditya P.Number of paths condition contains exactly one path that begins at node Start and terminates at node End. Depending on their location. Each additional condition in the program can increases the number of distinct paths by at least one.

languages.Copyright © 2013 Dorling Kindersley (India) Pvt. and regular expressions Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 78 .6 Strings. Ltd 2.

Mathur 79 Copyright © 2013 Dorling Kindersley (India) Pvt. a set of all strings consisting of zeros and ones is the language of binary numbers. “Hello world”. Examples: 1011. AaBc. A collection of strings also forms a language. Contents Foundations of Software Testing 2E Author: Aditya P. In this section we provide a brief introduction to strings and languages. A string serves as a test input. Ltd Strings .Strings play an important role in testing. For example.

We use an upper case letter such as X and Y to denote alphabets. X={0. Mathur 80 . we are concerned only with finite alphabets. ``horse". For example. Ltd A collection of symbols is known as an alphabet. 1} is an alphabet consisting of two symbols 0 and 1. cat. Another alphabet is Y={dog.Alphabet Copyright © 2013 Dorling Kindersley (India) Pvt. lion}that consists of four symbols ``dog". Though alphabets can be infinite. and ``lion". Contents Foundations of Software Testing 2E Author: Aditya P. horse. ``cat".

horse. Thus. q. r to denote strings. 0110 is a string over the alphabet {0. Mathur 81 . is denoted by ε. For example. |1011|=4 and |dog cat dog|=3. The length of a string is the number of symbols in that string. Foundations of Software Testing 2E Contents Author: Aditya P. also known as an empty string. Ltd A string over an alphabet X is any sequence of zero or more symbols that belong to X. dog cat dog dog lion is a string over the alphabet {dog. Note that ε denotes an empty string and also stands for “element of” when used with sets. We will use lower case letters such as p. Also. lion}.Strings over an Alphabet Copyright © 2013 Dorling Kindersley (India) Pvt. cat. A string of length 0. Given a string s. we denote its length by |s|. 1}.

s2|=|s1|+|s2|.Let s1 and s2 be two strings over alphabet X. Contents Foundations of Software Testing 2E Author: Aditya P. and two strings 011 and 101 over X. We write s1. for any string s. 1}. ε =s and ε. given the alphabet X={0. Mathur 82 Copyright © 2013 Dorling Kindersley (India) Pvt.s=s.101=011101. It is easy to see that |s1. Ltd String concatenation . we obtain 011. Also. we have s. For example.s2 to denote the concatenation of strings s1 and s2.

11. 0101}: A language containing three strings Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 83 . Ltd A set L of strings over an alphabet X is known as a language. 1}: ∅: The empty set {ε}: A language consisting only of one string of length zero {00. A language can be finite or infinite. The following sets are finite languages over the binary alphabet {0.Languages Copyright © 2013 Dorling Kindersley (India) Pvt.

L2. Contents Foundations of Software Testing 2E Author: Aditya P. respectively. Let r1 and r2 be two regular expressions over the alphabet X that denote. Ltd Regular expressions .r2 is a regular expression that denotes the set L1. sets L1 and L2.Given a finite alphabet X. Mathur 84 Copyright © 2013 Dorling Kindersley (India) Pvt. then a is a regular expression that denotes the set {a}. Then r1. the following are regular expressions over X: If a belongs to X.

respectively. If r denotes the set L then r* denotes the set {ε}∪ L+. Contents Foundations of Software Testing 2E Author: Aditya P. If r1 and r2 are regular expressions that denote. Mathur 85 Copyright © 2013 Dorling Kindersley (India) Pvt. is a regular expression.) .If r is a regular expression that denotes the set L then r+ is a regular expression that denotes the set obtained by concatenating L with itself one or more times also written as L+ Also. then r1r2 is also a regular expression that denotes the set L1 ∪ L2. Ltd Regular expressions (contd. sets L1 and L2. r* known as the Kleene closure of r.

Ltd Summary We have introduced mathematical preliminaries an understanding of which will be useful while you go through the remaining parts of this book.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 86 . Contents Foundations of Software Testing 2E Author: Aditya P. Exercises at the end of Chapter 2 will help you sharpen your understanding.

2013 Foundations of Software Testing 2E Contents Author: Aditya P. Ltd Chapter 3 Domain Partitioning Updated: July 12.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 87 .

Ltd Learning Objectives Essential black-box techniques for generating tests for functional testing. Mathur 88 .§  Equivalence class partitioning §  Boundary value analysis Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Cause effect graphing has been omitted from these slides.

system. These techniques are useful during functional testing where the objective is to test whether or not an application. Mathur 89 . Ltd Test generation techniques described in this chapter belong to the black-box testing category. unit. correctly implements the functionality as per the given requirements Contents Foundations of Software Testing 2E Author: Aditya P.Applications of test generation techniques Copyright © 2013 Dorling Kindersley (India) Pvt. or subsystem.

A Practitioners Guide to software Test Design Test Design Test Case Spec. Test Procedure Test incident Test log Test item transmittal report report Test summary Test generation techniques report Contents Foundations of Software Testing 2E Author: Aditya P.Requirements Test Plan Model Reference: Lee Copland. Ltd Functional Testing: Test Documents (IEEE829 Standard) . Spec. Mathur 90 Copyright © 2013 Dorling Kindersley (India) Pvt.

deliverables. approvals needed. resources. and any other special requirements e. Ltd tested. Test case spec: Lists inputs. expected outputs.Functional Testing: Documents Test Plan: Describe scope. features to be tested by this test case. approach. Test design spec: Identifies a subset of features to be tested and identifies the test cases to test the features in this subset. setting of environment variables and test procedures. responsibilities. Could be used at the system test level or at lower levels. test schedule.g. Dependencies with other test cases are specified here. items to be Copyright © 2013 Dorling Kindersley (India) Pvt. Foundations of Software Testing 2E Contents Author: Aditya P. Each test case has a unique ID for reference in other documents. Mathur 91 .

e. Contents Foundations of Software Testing 2E Author: Aditya P. Test summary: Summarize the results of testing activities and provide an evaluation. Test incident report: Document any special event that is recommended for further investigation. Mathur 92 . Test log: A log observations during the execution of a test.Functional Testing: Documents (contd) Copyright © 2013 Dorling Kindersley (India) Pvt. Test transmittal report: Identifies the test items being provided for testing.g. a database. Ltd Test procedure spec: Describe the procedure for executing a test case.

boundary value analysis.Copyright © 2013 Dorling Kindersley (India) Pvt. Each of these test generation techniques is black-box and useful for generating test cases during functional testing. Mathur 93 . and category partitioning. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Test generation techniques in this chapter Three techniques are considered: equivalence partitioning.

Ltd 3.Copyright © 2013 Dorling Kindersley (India) Pvt.2 The test selection problem Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 94 .

Requirements and test generation Copyright © 2013 Dorling Kindersley (India) Pvt. Rigorously specified requirements are often transformed into formal requirements using requirements specification languages such as Z. Contents Foundations of Software Testing 2E Author: Aditya P. sequence diagrams. more aptly ideas. Mathur 95 . are then specified rigorously using modeling elements such as use cases. Ltd Requirements serve as the starting point for the generation of tests. and statecharts in UML. and RSML. requirements may exist only in the minds of one or more people. S. During the initial phases of development. These requirements.

Mathur 96 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Test generation techniques Contents Foundations of Software Testing 2E Author: Aditya P.

Mathur 97 . In general there does not exist any algorithm to construct such a test set.Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Test selection problem Let D denote the input domain of a program P. there are heuristics and model based methods that can be used to generate tests that will reveal certain type of faults. The test selection problem is to select a subset T of tests such that execution of P against each element of T will reveal all errors in P. However.

Mathur 98 . Contents Foundations of Software Testing 2E Author: Aditya P. The problem of test selection is difficult due primarily to the size and complexity of the input domain of P.) The challenge is to construct a test set T⊆D that will reveal as many errors in P as possible. Ltd Test selection problem (contd.Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 99 .Copyright © 2013 Dorling Kindersley (India) Pvt. The complexity makes it harder to select individual tests. Ltd Exhaustive testing The large size of the input domain prevents a tester from exhaustively testing the program under test against all possible inputs. By ``exhaustive" testing we mean testing the given program against every element in its input domain. Contents Foundations of Software Testing 2E Author: Aditya P.

Foundations of Software Testing 2E Author: Aditya P. then the size of the input domain depends on the value of N. Assuming that P will be executed on a machine in which integers range from -32768 to 32767. If the size of the input sequence is limited to. then the input domain of P is infinitely large and P can never be tested exhaustively. Mathur 100 Contents Copyright © 2013 Dorling Kindersley (India) Pvt. If there is no limit on the size of the sequence that can be input. Calculate the size of the input domain. say Nmax>1.Consider program P that is required to sort a sequence of integers into ascending order. Ltd Large input domain . 32767]. the input domain of P consists of all possible sequences of integers in the range [-32768.

Foundations of Software Testing 2E Author: Aditya P.Complex input domain Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 101 Contents . For simplicity. assume that the employee record consists of the following items with their respective types and constraints: Calculate the size of the input domain. Ltd Consider a procedure P in a payroll processing system that takes an employee record as input and computes the weekly salary.

Ltd 3. Mathur 102 .3 Equivalence partitioning Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd Equivalence partitioning Test selection using equivalence partitioning allows a tester to subdivide the input domain into a relatively small number of sub-domains.Copyright © 2013 Dorling Kindersley (India) Pvt. Each subset is known as an equivalence class. say N>1. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 103 . as shown (next slide (a)). In strict mathematical terms. the sub-domains by definition are disjoint. The four subsets shown in (a) constitute a partition of the input domain while the subsets in (b) are not.

Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 104 . Ltd Subdomains Contents Foundations of Software Testing 2E Author: Aditya P.

within a class.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Program behavior and equivalence classes The equivalence classes are created assuming that the program under test exhibits the same behavior on all elements. Contents Foundations of Software Testing 2E Author: Aditya P.e. i. This assumption allow the tester to select exactly one test from each equivalence class resulting in a test suite of exactly N tests. Mathur 105 . tests.

Mathur 106 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Each of the two subsets. inputs (E) and the other containing all unexpected. E3. can be further subdivided into subsets on which the application is required to behave differently (e. U2). E2. or legal. E1.g. or illegal. Ltd Faults targeted .The entire set of inputs to any application can be divided into at least two subsets: one containing all the expected. and U1. inputs (U).

Mathur 107 Copyright © 2013 Dorling Kindersley (India) Pvt.) . Ltd Faults targeted (contd.Equivalence class partitioning selects tests that target any faults in the application that cause it to behave incorrectly when the input is in either of the two classes or their subsets. Contents Foundations of Software Testing 2E Author: Aditya P.

.Example 1 the only legal values of age are in the range [1.120] Contents Foundations of Software Testing 2E Author: Aditya P.. Let us suppose that . All integers Other integers [1. Mathur 108 Copyright © 2013 Dorling Kindersley (India) Pvt.120]..120] and a set U containing the remaining integers. Ltd Consider an application A that takes an integer denoted by age as input. The set of input values is now divided into a set E containing all integers in the range [1.

assume that the application is required to process all values in the range [1. Mathur 109 Copyright © 2013 Dorling Kindersley (India) Pvt.120] according to requirement R2. Thus...) . it is expected that all invalid inputs less than or equal to 1 are to be treated in one way while all greater than 120 are to be treated differently.Further. Contents Foundations of Software Testing 2E Author: Aditya P. E is further subdivided into two regions depending on the expected behavior. Ltd Example 1 (contd. Similarly. This leads to a subdivision of U into two categories.61] in accordance with requirement R1 and those in the range [62.

Ltd Example 1 (contd.All integers <1 [62-120] Copyright © 2013 Dorling Kindersley (India) Pvt..) >120 [1. Mathur 110 .61] Contents Foundations of Software Testing 2E Author: Aditya P.

Contents Foundations of Software Testing 2E Author: Aditya P. two regions containing expected inputs and two regions containing the unexpected inputs. i. Ltd Example 1 (contd. any test selected from the region [62..120] will reveal any fault with respect to R2. A similar expectation applies to the two regions containing the unexpected inputs.61] will reveal any fault with respect to R1. Similarly.) . Mathur 111 Copyright © 2013 Dorling Kindersley (India) Pvt.. It is expected that any single test selected from the range [1.e..Tests selected using the equivalence partitioning technique aim at targeting faults in the application under test with respect to inputs in any of the four regions.

The effectiveness can be improved through an unambiguous and complete specification of the requirements and carefully selected tests using the equivalence partitioning technique described in the following sections. the effectiveness of tests selected using equivalence partitioning is less than 1 for most practical applications. is judged by the ratio of the number of faults these tests are able to expose to the total faults lurking in A. As is the case with any test selection technique in software testing.The effectiveness of tests generated using equivalence partitioning for testing application A. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Effectiveness . Mathur 112 Copyright © 2013 Dorling Kindersley (India) Pvt.

An exception is raised if there is no file with name f. Contents Foundations of Software Testing 2E Author: Aditya P. Consider that wordCount method takes a word w and a filename f as input and returns the number of occurrences of w in the text contained in the file named f.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Example 2 This example shows a few ways to define equivalence classes based on the knowledge of requirements and the program text. Mathur 113 .

return(0).Example 2 (contd. f if (not exists(f) {raise exception.f)). Ltd begin . Contents Foundations of Software Testing 2E Author: Aditya P.) String w. f Input w. Using the partitioning method described in the return(getCount(w. if(empty(f))return(0). we obtain the equivalence end classes (next slide).} if(length(w)==0)return(0). examples above. Mathur 114 Copyright © 2013 Dorling Kindersley (India) Pvt.

Example 2 (contd. empty Copyright © 2013 Dorling Kindersley (India) Pvt. empty E4 null exists. not empty E5 null does not exist E6 null exists.) w f E1 non-null exists. Mathur 115 . not empty E2 non-null does not exist E3 non-null exists. Ltd Equivalence class Contents Foundations of Software Testing 2E Author: Aditya P.

) Copyright © 2013 Dorling Kindersley (India) Pvt.Example 2 (contd. whereas the number of equivalence classes derived with the knowledge of partial code is 6. and perhaps more. Of course. an experienced tester will likely derive the six equivalence classes given above. Mathur 116 . even before the code is available Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Note that the number of equivalence classes without any knowledge of the program code is 2.

Mathur 117 . suppose that a program outputs an integer. For example.Copyright © 2013 Dorling Kindersley (India) Pvt. It is worth asking: ``Does the program ever generate a 0? What are the maximum and minimum possible values of the output?" These two questions lead to two the following equivalence classes based on outputs: Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Equivalence classes based on program output In some cases the equivalence classes are based on the output generated by the program.

Mathur 118 .) E1: Output value v is 0. E2: Output value v is the maximum possible. E4: All other output values. Contents Foundations of Software Testing 2E Author: Aditya P. Thus. Based on the output equivalence classes one may now derive equivalence classes for the inputs.Copyright © 2013 Dorling Kindersley (India) Pvt. E3: Output value v is the minimum possible. each of the four classes given above might lead to one equivalence class consisting of inputs. Ltd Equivalence classes based on program output (contd.

52}} age: int {{-1}.0 {{-1. area: float area≥0. {3}} Contents Foundations of Software Testing 2E Author: Aditya P.90] {50}. {56}. {15. {75}. Mathur 119 . Classes One class with values speed ∈[60. inside the range and {92} two with values outside the range. {132}} letter:bool {{J}..Equivalence classes for variables: range Example Constraints Classes Copyright © 2013 Dorling Kindersley (India) Pvt.0}. Ltd Eq.

Mathur 120 . {Sue}.Equivalence Classes At least one containing all legal strings and one all Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Equivalence classes for variables: strings Example Constraints Classes firstname: string {{ε}. {Loooong Name}} illegal strings based on any constraints.

Ltd Equivalence classes for variables: enumeration Example Classes autocolor:{red.Equivalence Classes Constraints Each value in a separate class Copyright © 2013 Dorling Kindersley (India) Pvt. {green}} up:boolean {{true}. blue. green} {{red. {false}} Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 121 .} {blue}.

Contents Foundations of Software Testing 2E Author: Aditya P. one Copyright © 2013 Dorling Kindersley (India) Pvt. 20]}. 15]} containing the empty array. Mathur 122 .Equivalence Classes Constraints One class containing all legal arrays. Ltd Equivalence classes for variables: arrays Example Classes int [ ] aName: new int[3]. {[-9. 0. {[ ]}. 12. {[-10. and one containing a larger than expected array.

Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 123 . in C++. one must consider legal and illegal values for each component of the structure. or structures.Copyright © 2013 Dorling Kindersley (India) Pvt. While generating equivalence classes for such inputs. Ltd Equivalence classes for variables: compound data type Arrays in Java and records. The next example illustrates the derivation of equivalence classes for an input variable that has a compound type. are compound types. Such input types may arise while testing components of an application such as a function or an object.

char grades [200]. // Last name. } In-class exercise: Derive equivalence classes for each component of R and combine them! Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 124 . // First name. Ltd struct transcript { string fName. string lName. // Letter grades corresponding to course titles. // Course titles. string cTitle [200].Equivalence classes for variables: compound data type: Example Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 125 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd uni-dimensional partitioning .One way to partition the input domain is to consider one input variable at a time. Contents Foundations of Software Testing 2E Author: Aditya P. We refer to this style of partitioning as uni-dimensional equivalence partitioning or simply uni-dimensional partitioning. each input variable leads to a partition of the input domain. Thus. This type of partitioning is used commonly.

Multidimensional partitioning variables and define a relation on I. Multidimensional partitioning leads to a large number of equivalence classes that are difficult to manage manually. This procedure creates one partition consisting of several equivalence classes. Many classes so created might be infeasible. equivalence classes so created offer an increased variety of tests as is illustrated in the next section. Nevertheless. Ltd Another way is to consider the input domain I as the set product of the input . Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 126 Copyright © 2013 Dorling Kindersley (India) Pvt. We refer to this method as multidimensional equivalence partitioning or simply multidimensional partitioning.

Each of these inputs is expected to lie in the following ranges: 3≤ x≤7 and 5≤y≤9. Mathur 127 . This leads to the following six equivalence classes.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Partitioning Example Consider an application that requires two integer inputs x and y. For uni-dimensional partitioning we apply the partitioning guidelines to x and y individually. Contents Foundations of Software Testing 2E Author: Aditya P.

Mathur 128 . This leads to 9 equivalence classes.) y ignored. For multidimensional partitioning we consider the input domain to be the set product X x Y. Contents Foundations of Software Testing 2E Author: Aditya P. x ignored. Ltd Partitioning Example (contd.E1: x<3 E2: 3≤x≤7 E3: x>7 E4: y<5 E5: 5≤y≤9 E6: y>9 Copyright © 2013 Dorling Kindersley (India) Pvt.

y>9 E4: 3≤x≤7. y>9 Copyright © 2013 Dorling Kindersley (India) Pvt. 5≤y≤9 E3: x<3. 5≤y≤9 E6: 3≤x≤7.) Contents Foundations of Software Testing 2E Author: Aditya P. y>9 E7: >7. y<5 E2: x<3.E1: x<3. y<5 E5: 3≤x≤7. Ltd Partitioning Example (contd. 5≤y≤9 E9: x>7. Mathur 129 . y<5 E8: x>7.

y<5 E8: x>7.Partitioning Example (contd. y>9 E2: x<3. y>9 9 equivalence classes: Contents Foundations of Software Testing 2E Author: Aditya P.) Copyright © 2013 Dorling Kindersley (India) Pvt. y>9 E7: >7. Ltd 6 equivalence classes: E1: x<3. y<5 E5: 3≤x≤7. y<5 E3: x<3. 5≤y≤9 E9: x>7. 5≤y≤9 E6: 3≤x≤7. Mathur 130 . 5≤y≤9 E4: 3≤x≤7.

1. and any conditions associated with their use. Ltd Systematic procedure for equivalence partitioning . Identify the input domain: Read the requirements carefully and identify all input and output variables. also serve as input variables. Windows. an approximation to the input domain is the product of these sets. and other operating systems. Mathur 131 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Given the set of values each variable can assume. Environment variables. such as class variables used in the method under test and environment variables in Unix. their types.

Mathur 132 Copyright © 2013 Dorling Kindersley (India) Pvt. the equivalence classes based on an input variable partition the input domain. Each subset is an equivalence class. Values for which the program is expected to behave in the ``same way" are grouped together.) . Equivalence classing: Partition the set of values of each variable into disjoint subsets. Contents Foundations of Software Testing 2E Author: Aditya P. Together. Note that ``same way" needs to be defined by the tester. is done based on the the expected behavior of the program.2. Ltd Systematic procedure for equivalence partitioning (contd. partitioning the input domain using values of one variable.

3. The equivalence classes are combined using the multidimensional partitioning approach described earlier. Combine equivalence classes: This step is usually omitted and the equivalence classes defined for each variable are directly used to select test cases.) . Mathur 133 Copyright © 2013 Dorling Kindersley (India) Pvt. by not combining the equivalence classes. However. Contents Foundations of Software Testing 2E Author: Aditya P. one misses the opportunity to generate useful tests. Ltd Systematic procedure for equivalence partitioning (contd.

e. Identify infeasible equivalence classes: An infeasible equivalence class is one that contains a combination of input data that cannot be generated during test. Such an equivalence class might arise due to several reasons. data is input using commands available in the GUI. suppose that an application is tested via its GUI.Copyright © 2013 Dorling Kindersley (India) Pvt. The GUI might disallow invalid inputs by offering a palette of valid inputs only. i. There might also be constraints in the requirements that render certain equivalence infeasible. For example. Contents Foundations of Software Testing 2E Author: Aditya P.) 4. Mathur 134 . Ltd Systematic procedure for equivalence partitioning (contd.

An temperature change of 0 is not an option. Command temp causes CS to ask the operator to enter the amount by which the temperature is to be changed (tempch). Ltd The control software of BCS. Mathur Contents 135 Copyright © 2013 Dorling Kindersley (India) Pvt. abbreviated as CS. Foundations of Software Testing 2E Author: Aditya P. is required to offer several options. shut down the boiler (shut).10 in increments of 5 degrees Fahrenheit. is used by a human operator to give one of four commands (cmd): change the boiler temperature (temp).Boiler control example (BCS) of the options. C (for control).. and cancel the request (cancel). Values of tempch are in the range -10. One .

if V is set to file. However. The file name is obtained from variable F. the operator is asked to enter one of the three commands via a GUI. together with the value of the temperature to be changed if the command is temp. Contents Foundations of Software Testing 2E Author: Aditya P. If V is set to GUI. Ltd BCS: example (contd.) . The command file may contain any one of the three commands.Selection of option C forces the BCS to examine variable V. Mathur 136 Copyright © 2013 Dorling Kindersley (India) Pvt. BCS obtains the command from a command file.

shut. file} F: file name if V is set to “file. Mathur 137 . F: Environment variables (temp.) V.V F cmd: command Copyright © 2013 Dorling Kindersley (India) Pvt. cancel) tempch GUI cmd Control Software (CS) tempch: desired temperature change (-10.. Ltd BCS: example (contd.” Contents Foundations of Software Testing 2E Author: Aditya P.10) datafile V ∈{GUI.

Mathur 138 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.Values of V and F can be altered by a different module in BCS. In response to temp and shut commands.) . Ltd BCS: example (contd. the control software is required to generate appropriate signals to be sent to the boiler heating system.

) . -5. 5. The tester takes on the role of an operator and interacts with the CS via a GUI. Mathur 139 Copyright © 2013 Dorling Kindersley (India) Pvt. and 10. We refer to these four values of tempch as tvalid while all other values as tinvalid.We assume that the control software is to be tested in a simulated environment. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd BCS: example (contd. the only options available for the value of tempch are -10. The GUI forces the tester to select from a limited set of values as specified in the requirements. For example.

These are listed in the following table. Mathur 140 Copyright © 2013 Dorling Kindersley (India) Pvt. Identify input domain .The first step in generating equivalence partitions is to identify the (approximate) input domain. Recall that the domain identified in this step will likely be a superset of the complete input domain of the control software. First we examine the requirements. and values. their types. Contents Foundations of Software Testing 2E Author: Aditya P. identify input variables. Ltd BCS: 1.

Variable Kind Type Value(s) V Environment Enumerated File. GUI F Environment String A file name cmd Input via GUI/File Enumerated {temp. Mathur 141 . types. -5. shut} tempch Input via GUI/File Enumerated {-10. values Contents Foundations of Software Testing 2E Author: Aditya P. cancel. 10} Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd BCS: Variables. 5.

shut. Ltd BCS: Input domain Input domain⊆S=V×F×cmd×tempch Sample values in the input domain (--: don’t care): (GUI. shut. cmdfile. --). cmdfile.Copyright © 2013 Dorling Kindersley (India) Pvt. (file. 0) Does this belong to the input domain? Contents Foundations of Software Testing 2E Author: Aditya P. --. temp. --) (file. Mathur 142 .

{finvalid}} cmd {{temp}. Equivalence classing Contents Foundations of Software Testing 2E Author: Aditya P.Variable Partition V {{GUI}. {undefined}} F {{fvalid}. {file}. Mathur 143 . {shut}. Ltd BCS: 2. {tinvalid}} Copyright © 2013 Dorling Kindersley (India) Pvt. {cinvalid}} tempch {{tvalid}. {cancel}.

Sample equivalence class: {(GUI. Each value is a potential input to the BCS.) for the control software. There are a total of 3×4×2×5=120 equivalence classes. finvalid. Combine equivalence classes (contd. and fvalid denote sets of values. temp. Contents Foundations of Software Testing 2E Author: Aditya P. “undefined” denotes one value. Mathur 144 . fvalid. For example. -10)} denotes an infinite set of values obtained by replacing fvalid by a string that corresponds to the name of an existing file. tvalid. -10)} Note that each of the classes listed above represents an infinite number of input values Copyright © 2013 Dorling Kindersley (India) Pvt. {(GUI}}.Note that tinvalid. temp. Ltd BCS: 3. fvalid.

{(V.BCS: 4. F. cinvalid}. all equivalence classes that match the following template are infeasible. Exercise: How many additional equivalence classes are infeasible? Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Note that the GUI requests for the amount by which the boiler temperature is to be changed only when the operator selects temp for cmd. shut. tvalid∪ tinvalid)} This parent-child relationship between cmd and tempch renders infeasible a total of 3×2×3×5=90 equivalence classes. Discard infeasible equivalence classes Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 145 . {cancel. Thus.

Ltd BCS: 4. Discard infeasible equivalence classes (contd. Mathur 146 Copyright © 2013 Dorling Kindersley (India) Pvt.) . Contents Foundations of Software Testing 2E Author: Aditya P. we are left with a total of 18 testable (or feasible) equivalence classes.After having discarded all infeasible equivalence classes.

a tester simply selects one test that serves as a representative of each equivalence class. Contents Foundations of Software Testing 2E Author: Aditya P. complications could arise in the presence of infeasible data and don't care values.Selecting test data Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Given a set of equivalence classes that form a partition of the input domain. Mathur 147 . Exercise: Generate sample tests for BCS from the remaining feasible equivalence classes. it is relatively straightforward to select tests. However. In the most general case.

Mathur 148 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. For example. Ltd GUI design and equivalence classes . However.While designing equivalence classes for programs that obtain input exclusively from a keyboard. The application places a constraint on an input variable X such that it can assume integral values in the range 0.4. the requirement for an application. one must account for the possibility of errors in data entry. testing must account for the possibility that a user may inadvertently enter a value for X that is out of range..

In such a situation it is impossible to test the application with a value of X that is out of range. Ltd GUI design and equivalence classes (contd. See figure on the next slide.Suppose that all data entry to the application is via a GUI front end.) . Suppose also that the GUI offers exactly five correct choices to the user for X. Contents Foundations of Software Testing 2E Author: Aditya P. Hence only the correct values of X will be input. Mathur 149 Copyright © 2013 Dorling Kindersley (India) Pvt.

) Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd GUI design and equivalence classes (contd. Mathur 150 .

Mathur 151 .4 Boundary value analysis Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 3.Copyright © 2013 Dorling Kindersley (India) Pvt.

lies at the boundary of the equivalence classes x≤0 and x>0. the value x=0. For example. when M is tested against x=0 but not if the input test set is. this fault is revealed. Obviously. 7} derived using equivalence partitioning. suppose that method M is required to compute a function f1 when x≤ 0 is true and function f2 otherwise. M has an error due to which it computes f1 for x<0 and f2 otherwise. though not necessarily. Foundations of Software Testing 2E Contents Author: Aditya P. In this example. However. for example. Ltd Experience indicates that programmers make mistakes in processing values at and near the . Mathur 152 Copyright © 2013 Dorling Kindersley (India) Pvt.Errors at the boundaries boundaries of equivalence classes. {-4.

boundary value analysis focuses on tests at and near the boundaries of equivalence classes. tests derived using either of the two techniques may overlap. Certainly. Mathur 153 Copyright © 2013 Dorling Kindersley (India) Pvt. While equivalence partitioning selects tests from within equivalence classes. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Boundary value analysis (BVA) .Boundary value analysis is a test selection technique that targets faults in applications at the boundaries of equivalence classes.

Mathur 154 Copyright © 2013 Dorling Kindersley (India) Pvt. a single partition of an input domain can be created using multidimensional partitioning. This leads to as many partitions as there are input variables. We will generate several sub-domains in this step.BVA: Procedure Partition the input domain using uni-dimensional partitioning. Alternately. Ltd 1  . Contents Foundations of Software Testing 2E Author: Aditya P. Boundaries may also be identified using special relationships amongst the inputs. 3  Select test data such that each boundary value occurs in at least one test input. 2  Identify the boundaries for each partition.

Equivalence classes for qty: E4: Values less than 1.BVA: Example: 1. E3: Values greater than 999. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Assuming that an item code must be in the range 99.100... E6: Values greater than 100. E5: Values in the range. Equivalence classes for code: E1: Values less than 99. Mathur 155 .999 and quantity in the range 1. E2: Values in the range. Create equivalence classes Copyright © 2013 Dorling Kindersley (India) Pvt.

Identify boundaries * x 99 E1 100 998 * * E2 0 * E4 x 1 2 99 * * E5 1000 x * 999 E3 Copyright © 2013 Dorling Kindersley (India) Pvt. Boundaries are indicated with an x.BVA: Example: 2. Points near the boundary are marked *. Ltd 98 101 x * 100 E6 Equivalence classes and boundaries for findPrice. Mathur Contents 156 . Foundations of Software Testing 2E Author: Aditya P.

Mathur 157 Copyright © 2013 Dorling Kindersley (India) Pvt. qty=2). Consider the . qty=1).BVA: Example: 3. t5: (code=999. Construct test set Test selection based on the boundary value analysis technique requires that tests following test set: T={ t1: (code=98. qty included. values at and around the boundary. qty=101) } Contents Foundations of Software Testing 2E Author: Aditya P. for each variable. qty=100). t4: (code=998. t2: (code=99. Ltd must include. qty=0). Illegal values of code and t3: (code=100. qty=99). t6: (code=1000.

11. Contents Foundations of Software Testing 2E Author: Aditya P.12. Highly recommended: Go through Example 3. Mathur 158 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Is T the best possible test set for findPrice? Answer this question based on T’s . Is there an advantage of separating the invalid values of code and age into different test cases? Answer: Refer to Example 3.BVA: In-class exercise ability to detect missing code for checking the validity of age.

Additional tests may be obtained when using a partition of the input domain obtained by taking the product of equivalence classes created using individual variables.BVA: Recommendations Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Relationships amongst the input variables must be examined carefully while identifying boundaries along the input domain. Mathur 159 . This examination may lead to boundaries that are not evident from equivalence classes obtained from the input and output variables. Contents Foundations of Software Testing 2E Author: Aditya P.

Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 160 .4. Ltd 4. Tests using predicate syntax Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd Where do predicates arise? Predicates arise from requirements in a variety of applications.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 161 . 1997. Here is an example from Paradkar.” Annals of Software Engineering.” V 4. and Vouk. “Specification based testing using cause-effect graphs. A boiler needs to be shut down when the following conditions hold: Contents Foundations of Software Testing 2E Author: Aditya P. Tai. pp 133-157.

(c) 4. 5. Mathur 162 . (b) 3. Contents Foundations of Software Testing 2E Author: Aditya P. (d) Boiler in degraded mode when either is true. (e) The boiler is to be shut down when a or b is true or the boiler is in degraded mode and the steam meter fails. Ltd 1.  The water level in the boiler is above Y lbs. We combine these five conditions to form a compound condition (predicate) for boiler shutdown.Boiler shutdown conditions Copyright © 2013 Dorling Kindersley (India) Pvt.  A pump monitor has failed.  The water level in the boiler is below X lbs.  Steam meter has failed.  A water pump has failed. (a) 2.

Boiler shutdown conditions Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 163 .” The goal of predicate-based test generation is to generate tests from a predicate p that guarantee the detection of any error that belongs to a class of errors in the coding of p. Ltd Denoting the five conditions above as a through e. we obtain the following Boolean expression E that when true must force a boiler shutdown: E=a+b+(c+d)e where the + sign indicates “OR” and a multiplication indicates “AND.

. also known as a Boolean expression. pr: (printer_status=ON) ∧ (printer_tray!= empty) Contents Foundations of Software Testing 2E Author: Aditya P. Ltd A condition is represented formally as a predicate.” This statement consists of a condition part and an action part. Mathur 164 Copyright © 2013 Dorling Kindersley (India) Pvt. The following predicate represents the condition part of the statement. consider the requirement ``if the printer is ON and has paper then send document to printer.Another example For example.

Ltd Summary Equivalence partitioning and boundary value analysis are the most commonly used methods for test generation while doing functional testing. Mathur 165 . Contents Foundations of Software Testing 2E Author: Aditya P. one can apply these techniques to generate tests for f. Given a function f to be tested in an application.Copyright © 2013 Dorling Kindersley (India) Pvt.

2013 Foundations of Software Testing 2E Contents Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Chapter 4 Predicate Analysis Updated: July 12. Mathur 166 .

Mathur 167 . Ltd Learning Objectives Contents Foundations of Software Testing 2E Author: Aditya P.§  Domain testing §  Cause-effect graphing §  Test generation from predicates Copyright © 2013 Dorling Kindersley (India) Pvt.

4. Ltd 4.4 Tests using predicate syntax 4. Mathur 168 .1: A fault model Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Contents Foundations of Software Testing 2E Author: Aditya P. b. and d are integer variables and e is a Boolean variable. c. Here a.Fault model for predicate testing Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 169 . Ltd What faults are we targeting when testing for the correct implementation of predicates? Boolean operator fault: Suppose that the specification of a software module requires that an action be performed when the condition (a<b) ∨ (c>d) ∧e is true.

Mathur 170 . Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Boolean operator faults Correct predicate: (a<b) ∨ (c>d) ∧e (a<b) ∧ (c>d) ∧e Incorrect Boolean operator (a<b) ∨ ! (c>d) ∧e Incorrect negation operator (a<b) ∧(c>d) ∨ e Incorrect Boolean operators (a<b) ∨ (e>d) ∧c Incorrect Boolean variable.Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 171 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Relational operator faults Correct predicate: (a<b) ∨ (c>d) ∧e (a==b) ∨ (c>d) ∧e Incorrect relational operator (a==b) ∨ (c≤d) ∧e Two relational operator faults (a==b) ∨ (c>d) ∨ e Incorrect Boolean operators Contents Foundations of Software Testing 2E Author: Aditya P.

Arithmetic expression faults Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Correct predicate: Ec: e1 relop1 e2. Contents Foundations of Software Testing 2E Author: Aditya P. Ei has an off-by-ε fault if |e3-e4|= ε for any test case for which e1=e2. Mathur 172 . Assume that Ec and Ei use the same set of variables. Ei has an off-by-ε* fault if |e3-e4|≥ ε for any test case for which e1=e2. Incorrect predicate: Ei: : e3 relop2 e4. Ei has an off-by-ε+ fault if |e3-e4|> ε for any test case for which e1=e2.

Contents Foundations of Software Testing 2E Author: Aditya P. Given c>0. c=2> Ei: a<b-1.Correct predicate: Ec: a<(b+c). Ei: a<b. Ei has an off-by-1* fault as |a-(b+1)|≥ 1 for any test case for which a=b+c. Assume ε=1. Given c=1. Ei has an off-by-1+ fault as |a-(b-1)|>1 for any test case for which a=b+c. b=2. <a=4. Ei has an off-by-1 fault as |a-b|= 1 for a test case for which a=b+c. Ltd Arithmetic expression faults: Examples . c=1>. <a=3. b=1. Mathur 173 Copyright © 2013 Dorling Kindersley (India) Pvt. <a=2. b=2. e.g. c=1>. Given c=2. Ei: a<b+1.

Find an incorrect version of Ec that has off-by-1 fault. Ltd Arithmetic expression faults: In class exercise Given the correct predicate: Ec: 2*X+Y>2. Mathur 174 . Contents Foundations of Software Testing 2E Author: Aditya P. Assume ε=1. Find an incorrect version of Ec that has off-by-1* fault. Find an incorrect version of Ec that has off-by-1+ fault.Copyright © 2013 Dorling Kindersley (India) Pvt.

Such a test set is said to guarantee the detection of any fault of the kind in the fault model introduced above.Given a correct predicate pc. Contents Foundations of Software Testing 2E Author: Aditya P. the goal of predicate testing is to generate a test set T such that there is at least one test case t∈ T for which pc and its faulty version pi. Mathur 175 Copyright © 2013 Dorling Kindersley (India) Pvt. evaluate to different truth values. Ltd Goal of predicate testing .

b=0. Contents Foundations of Software Testing 2E Author: Aditya P. However. t2} where t1: <a=0. b=1. the fault is revealed by t2 as pc evaluates to true and pi to false when evaluated against t2. c=0> and t2: <a=0. The fault in pi is not revealed by t1 as both pc and pi evaluate to false when evaluated against t1. Ltd Goal of predicate testing (contd.As an example. Consider a test set T={t1. suppose that pc: a<b+c and pi: a>b+c. Mathur 176 Copyright © 2013 Dorling Kindersley (India) Pvt. c=1>.) .

Ltd Missing or extra Boolean variable faults Correct predicate: a ∨ b Missing Boolean variable fault: a Extra Boolean variable fault: a ∨ b∧c Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 177 .

Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 178 . Ltd 4.1: Predicate constraints Contents Foundations of Software Testing 2E Author: Aditya P.4.4 Tests using predicate syntax 4.

f. Contents Foundations of Software Testing 2E Author: Aditya P. -ε} A BR symbol is a constraint on a Boolean variable or a relational expression. >. <. Ltd Consider the following Boolean-Relational set of BR-symbols: BR={t. A test case that satisfies this constraint for E must cause E to evaluate to false. =.Predicate constraints: BR symbols Copyright © 2013 Dorling Kindersley (India) Pvt. For example. consider the predicate E: a<b and the constraint “>” . Mathur 179 . +ε.

Ltd Infeasible constraints . For example.A constraint C is considered infeasible for predicate pr if there exists no input values for the variables in pr that satisfy c. Mathur 180 Copyright © 2013 Dorling Kindersley (India) Pvt. the constraint t is infeasible for the predicate a>b∧ b>d if it is known that d>a. Contents Foundations of Software Testing 2E Author: Aditya P.

Contents Foundations of Software Testing 2E Author: Aditya P. it offers hints on what the values of the variables should be for pr to satisfy C.e. one for each Boolean variable or relational expression in pr. if each component of pr satisfies the corresponding constraint in C when evaluated against t. i. Ltd Let pr denote a predicate with n. Test case t satisfies C for predicate pr.. n>0. Constraint C for predicate pr guides the development of a test for pr. ∨ and ∧ operators. Mathur 181 . When clear from context. A predicate constraint C for predicate pr is a sequence of (n+1) BR symbols. we refer to ``predicate constraint" as simply constraint.Predicate constraints Copyright © 2013 Dorling Kindersley (India) Pvt.

pr(C) =true. respectively. and for any C in Sf. Ltd pr(C) denotes the value of predicate pr evaluated using a test case that satisfies C. Mathur 182 . A set of constraints S is partitioned into subsets St and Sf. S= St ∪ Sf. such that for each C in St. pr(C) =false. Contents Foundations of Software Testing 2E Author: Aditya P. C is referred to as a true constraint when pr(C) is true and a false constraint otherwise.True and false constraints Copyright © 2013 Dorling Kindersley (India) Pvt.

r=1. =. The following test case satisfies C for pr. s=2. v=0> The following test case does not satisfy C for pr. v=2> Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 183 . <b=true. u=1. >). s=1. Ltd Predicate constraints: Example Consider the predicate pr: b∧ (r<s) ∨ (u≥v) and a constraint C: (t. r=1. <b=true. u=1.

3: Predicate testing criteria Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 4.4 Tests using predicate syntax 4.4.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 184 .

and BRE. Mathur 185 Copyright © 2013 Dorling Kindersley (India) Pvt. BRO. Contents Foundations of Software Testing 2E Author: Aditya P. faults correspond to the fault model we discussed earlier. Ltd Predicate testing: criteria . We will discuss three such criteria named BOR.Given a predicate pr. we want to generate a test set T such that •  T is minimal and •  T guarantees the detection of any fault in the implementation of pr.

Ltd Predicate testing: BOR testing criterion A test set T that satisfies the BOR testing criterion for a compound predicate pr.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 186 . guarantees the detection of single or multiple Boolean operator faults in the implementation of pr. T is referred to as a BOR-adequate test set and sometimes written as TBOR. Contents Foundations of Software Testing 2E Author: Aditya P.

guarantees the detection of single Boolean operator and relational operator faults in the implementation of pr. Mathur 187 Copyright © 2013 Dorling Kindersley (India) Pvt.A test set T that satisfies the BRO testing criterion for a compound predicate pr. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Predicate testing: BRO testing criterion . T is referred to as a BRO-adequate test set and sometimes written as TBRO.

Contents Foundations of Software Testing 2E Author: Aditya P. relational expression. Mathur 188 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Predicate testing: BRE testing criterion A test set T that satisfies the BRE testing criterion for a compound predicate pr. and arithmetic expression faults in the implementation of pr. guarantees the detection of single Boolean operator. T is referred to as a BRE-adequate test set and sometimes written as TBRE.

x∈{BOR.BRE}. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 189 Copyright © 2013 Dorling Kindersley (India) Pvt. be a test set derived from predicate pr.Let Tx. Tx is said to guarantee the detection of faults in pf if for some t∈Tx. relational operator fault. BRO. Let pf be another predicate obtained from pr by injecting single or multiple faults of one of three kinds: Boolean operator fault. and arithmetic expression fault. Ltd Predicate testing: guaranteeing fault detection . p(t)≠ pf(t).

d=2 >. t).Guaranteeing fault detection: example Copyright © 2013 Dorling Kindersley (India) Pvt. b=0. c=1. (f. t)} Let TBOR={t1. Mathur 190 . t1: <a=1. t). a<b is true and c<d is also true. b=2. c=1. Ltd Let pr=a<b ∧ c>d Constraint set S={(t. d=0 >.e. Satisfies (t. t2: <a=1. Satisfies (t. Satisfies (f. (t. f) t3: <a=1. d=0 >.f). t2. t) Contents Foundations of Software Testing 2E Author: Aditya P. c=1. b=2. i. t3} is a BOR adequate test set that satisfies S.

Mathur 191 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Guaranteeing fault detection: In class exercise Generate single Boolean operator faults in pr: a<b ∧ c>d and show that T guarantees the detection of each fault. Contents Foundations of Software Testing 2E Author: Aditya P.

BRO. Mathur 192 .4. Ltd 4.1: BOR. and BRE adequate tests Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.4 Tests using predicate syntax 4.

and BRE adequate tests Define the cross product of two sets A and B as: A×B={(a. such that each element of A appears at least once as u and each element of B appears once as v.Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. BRO.v)|u∈A. Mathur 193 . Ltd Algorithms for generating BOR.b)|a∈A and b∈B} The onto product of two sets A and B is defined as: A⊗B={(u. v∈B.} Note that A⊗B is a minimal set.

<). <). Mathur 194 . (>.Copyright © 2013 Dorling Kindersley (India) Pvt. (=. <). =. Ltd Set products: Example Let A={t. (=. (=. f). <} A×B={(t. (t. (>. >} and B={f.<)} A⊗B ={(t. (>. f). f).f).<)} Any other possibilities for A⊗B? Contents Foundations of Software Testing 2E Author: Aditya P.

An illustration follows. Ltd See page 184 for a formal algorithm. Mathur 195 . ∧ a<b c>d Contents Foundations of Software Testing 2E Author: Aditya P.Generation of BOR constraint set Copyright © 2013 Dorling Kindersley (India) Pvt. generate syntax tree of pr. We want to generate TBOR for pr: a<b ∧ c>d First.

Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. where SNt is the true constraint set. Mathur 196 . we use the following notation: SN= SNt ∪ SNf is the constraint set. and SNf is the false constraint. Ltd Generation of the BOR constraint set Given node N in the syntax tree for predicate pr.

(f)} SN2= N2 {(t). (f)}. label each leaf node with the constraint set {(t). and so on for convenience. N2. Mathur 197 . Ltd Second. Contents Foundations of Software Testing 2E Author: Aditya P.Generation of the BOR constraint set (contd.) Copyright © 2013 Dorling Kindersley (India) Pvt. (f)} Notice that N1 and N2 are direct descendants of N3 which is an AND-node. We label the nodes as N1. N3 N1 SN1= ∧ c>d a<b {(t).

in this . (f. compute the constraint set for the next higher node in the syntax tree. Ltd Third. For an AND node. t). t). t)}∪{(t. f)} Contents Foundations of Software Testing 2E Author: Aditya P.) case N3.t). (f)} a<b = ({(f)} ×{(t)})∪({(t)}× {(f)}) = {(f.{(t. the formulae used are the following. SN3={(t.Generation of the BOR constraint set (contd. t)} ∧ N2 N1 SN3f = (SN1f ×{t2})∪({t1}× SN2f c>d {(t). f)} N3 {(t). Mathur 198 Copyright © 2013 Dorling Kindersley (India) Pvt. (f)} = {(f. (t. f)} SN3t = SN1t ⊗ SN2t ={(t)} ⊗ {(t)}={(t.

c=1. t) t3=<a=1. b=0. (f)} a<b {(t). (t. we have computed the BOR constraint set for the root node of . Ltd As per our objective.t). t) t2=<a=1. (f)} t1=<a=1. c=6. SN3={(t. d=5> (t. t). c=6. t3} ∧ N2 N1 c>d {(t). f) Contents Foundations of Software Testing 2E Author: Aditya P. d=2> (t. t2. (f. d=5> (f.Generation of TBOR the AST(pr). b=2. b=2. Here is one possible test set. Mathur 199 Copyright © 2013 Dorling Kindersley (India) Pvt. f)} SN3 contains a sequence of three constraints and N3 hence we get a minimal test set consisting of three test cases. TBOR ={t1. We can now generate a test set using the BOR constraint set associated with the root node.

Contents Foundations of Software Testing 2E Author: Aditya P.See pages 187-188 for a formal algorithm. Mathur 200 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Generation of BRO constraint set . Recall that a test set adequate with respect to a BRO constraint set for predicate pr. guarantees the detection of all combinations of single or multiple Boolean operator and relational operator faults. An illustration follows.

(=). (=)} Sf={(>)} Note: tN denotes an element of StN and fN denotes an element of SfN Foundations of Software Testing 2E Author: Aditya P.BRO constraint set The BRO constraint set S for relational expression e1 relop e2: Copyright © 2013 Dorling Kindersley (India) Pvt. (>)} relop: ≤ St={(<). Mathur 201 Contents . (<)} Sf={(<)} relop: = St={(=)} Sf={(<). (=)} Sf={(=). (>)} relop: < St={(<)} Sf={(=). (<)} Separation of S into its true (St) and false (Sf)components: relop: > St={(>)} relop: ≥ St={(>). Ltd S={(>).

BRO constraint set: Example Copyright © 2013 Dorling Kindersley (India) Pvt. ∨ N4 ∧ r>s N1 a+b<c N6 ! p N5 N3 N2 Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 202 . Ltd pr: (a+b<c)∧!p ∨ (r>s) Step 1: Construct the AST for the given predicate.

) ∨ N4 N6 ∧ r>s N1 a+b<c {(>). Ltd Step 2: Label each leaf node with its constraint set S. (f)} Contents Foundations of Software Testing 2E Author: Aditya P. N5 {(>). (<)} N3 ! p Copyright © 2013 Dorling Kindersley (India) Pvt. (=). (=). Mathur 203 . (<)} N2 {(t).BRO constraint set: Example (contd.

) StN3=SN2f={(f)} Copyright © 2013 Dorling Kindersley (India) Pvt.=)} ×{(f)}) ∪ {(<)} ×{(t)}) ={(>. f)} SfN4= (SfN1 × {(tN3)}) ∪ ({(tN1)} × SfN3) =({(>. f). SfN3=SN2t= {(t)} StN4=SN1t ⊗ SN3t={(<)} ⊗{(f)}={(<. Ltd Step 2: Traverse the tree and compute constraint set for each internal node.BRO constraint set: Example (contd. (<. (=. f)} ∪ {(<. (=. f). t)} Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 204 . t)} ={(>. f).

(=). (<)} N3 {(f). f).∨ {(<. Mathur 205 Copyright © 2013 Dorling Kindersley (India) Pvt. {t)} N2 {(t). t)} N4 ∧ r>s N1 a+b<c {(>). f). (=). f). (<. (=.) . Ltd BRO constraint set: Example (contd. (>. (f)} Contents Foundations of Software Testing 2E Author: Aditya P. (<)} N6 ! p N5 {(>).

t)} ⊗{(=). Mathur 206 .(<)}={(<.f.f).BRO constraint set: Example (contd.=)} StN6= (StN4 × {(fN5)})∪ ({(fN4)} × StN5) =({(<.f. Ltd Next compute the constraint set for the rot node (this is an OR-node).f.(>.f. f)} ={(>.f)} ×{(>)}) ={(<.<).>)} Contents Foundations of Software Testing 2E Author: Aditya P.=).f. (=.t. SfN6=SfN4 ⊗ SfN5 ={(>.(=.(<.f).=)} ∪ {(>.=).) Copyright © 2013 Dorling Kindersley (India) Pvt.(<.>)} ={(<.f)} ×{(=)}) ∪ {(>.f.

(>.(<. (<)} N3 {(f). f).f. (=. (<.=).f.(>. (=). (=. {t)} ! p N2 {(t).=). Mathur Contents 207 . f). t)} ∨ N6 N4 ∧ N1 a+b<c {(>).=).<).t. (<)} r>s {(>). (<. (=).) pr: (a+b<c)∧!p ∨ (r>s) {(>. Ltd BRO constraint set: Example (contd.f.f.Constraint set for Copyright © 2013 Dorling Kindersley (India) Pvt.>)} {(<. f). (f)} Foundations of Software Testing 2E N5 Author: Aditya P.

=).f.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 208 . {(>. (<. construct TBRO . Ltd BRO constraint set: In-class exercise Given the constraint set for pr: (a+b<c)∧!p ∨ (r>s).f.(<.=).(>.f. (=.=).f.>)} Contents Foundations of Software Testing 2E Author: Aditya P.t.<).

Mathur 209 .4.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 4.5: BOR constraints for non-singular expressions Contents Foundations of Software Testing 2E Author: Aditya P.4 Tests using predicate syntax 4.

Ltd BOR constraints for non-singular expressions . Contents Foundations of Software Testing 2E Author: Aditya P. and their mutually singular components. We will now learn how to generate BOR constraints for non-singular predicates. Recall that a singular predicate contains only one occurrence of each variable. their respective disjunctive normal forms (DNF).Test generation procedures described so far are for singular predicates. First. let us look at some non-singular expressions. Mathur 210 Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd Non-singular expressions and DNF: Examples Contents Foundations of Software Testing 2E Author: Aditya P. de Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 211 . !b+!c+ cde a(bc+!b+de) abc+a!b+ade a.Predicate (pr) DNF Mutually singular components in pr ab(b+c) abb+abc a. b(b+c) a(bc+ bd) abc+abd a. (bc+bd) a(!b+!c)+cde a!ba +a!c+cde a. bc+!b.

Ltd Generating BOR constraints for non-singular expressions We proceed in two steps. Next. Contents Foundations of Software Testing 2E Author: Aditya P. First we examine the Meaning Impact (MI) procedure for generating a minimal set of constraints from a possibly non-singular predicate.Copyright © 2013 Dorling Kindersley (India) Pvt. we examine the procedure to generate BOR constraint set for a non-singular predicate. Mathur 212 .

The MI procedure is on page 193 and is illustrated next. the MI procedure produces a set of constraints SE that guarantees the detection of missing or extra NOT (!) operator faults in the implementation of E.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Meaning Impact (MI) procedure Given Boolean expression E in DNF. Mathur 213 . Contents Foundations of Software Testing 2E Author: Aditya P.

For example. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Consider the non-singular predicate: a(bc+!bd). c. and as per common convention we have omitted the Boolean AND operator. Mathur 214 . a could represent r<s. ! is the Boolean NOT operator. and d are Boolean variables and also referred to as literals. b. Note that a. Each literal represents a condition.MI procedure: An Example Copyright © 2013 Dorling Kindersley (India) Pvt. Recall that + is the Boolean OR operator. For example bc is the same as b∧c. Its DNF equivalent is: E=abc+a!bd.

are to be interpreted similarly.t). and d. Step 1: Construct a constraint set Te1 for e1 that makes e1 true.t. Te1 ={(t.c. Contents Foundations of Software Testing 2E Author: Aditya P.t.t.f. (t. respectively.t. Mathur 215 . we can write E=e1+e2. Similarly construct Te2 for e2 that makes e2 true.f.t. where e1=abc and e2=a!bd. (t.t). b. The second element.) Copyright © 2013 Dorling Kindersley (India) Pvt. Clearly.MI procedure: Example (contd.f)} Te2 ={(t.f. and others.t)} Note that the four t’s in the first element of Te1 denote the values of the Boolean variables a. Ltd Step 0: Express E in DNF notation.

t.) Copyright © 2013 Dorling Kindersley (India) Pvt. Note that this step will lead TSei ∩TSej =∅.t.MI procedure: Example (contd.f)} TSe2 ={(t.t). There are no common constraints between Te1 and Te2 in our example.t. Hence we get: TSe1 ={(t. Mathur 216 . remove the constraints that are in any other Tej.f.t. (t.t.t). This gives us TSei and TSej. (t.t)} Contents Foundations of Software Testing 2E Author: Aditya P.f. Ltd Step 2: From each Tei .f.

(t. StE ={(t. Check it out! Contents Foundations of Software Testing 2E Author: Aditya P. StE is minimal.t.t).t.) Copyright © 2013 Dorling Kindersley (India) Pvt.f)} Note that for each constraint x in StE we get E(x)=true. Also. Ltd Step 3: Construct StE by selecting one element from each Te.MI procedure: Example (contd.f.f. Mathur 217 .

Contents Foundations of Software Testing 2E Author: Aditya P. We get the following six sets. derive constraints Fe that make e true. e11= !abc e21= a!bc e31= ab!c e12= !a!bd e22= abd e32= a!b!d From each term e above. obtain terms by complementing each literal. one at a time.) Step 4: For each term in E.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 218 . Ltd MI procedure: Example (contd.

f)} Contents Foundations of Software Testing 2E Author: Aditya P.t.t.t).f)} Fe21= {(t.f.f.) Fe11= {(f. (t. Mathur 219 .t.Copyright © 2013 Dorling Kindersley (India) Pvt.f.t)} Fe32= {(t.f. Ltd MI procedure: Example (contd.t.t.t. (t.f)} Fe12= {(f.f).t.f.t).t. (t.t.t.f.f)} Fe31= {(t.t).t). (t. (f.t.f.f.t)} Fe22= {(t. (f.f.t).f.t.t.f.

FSe11= FSe11 FSe21= {(t.t. Ltd MI procedure: Example (contd.t. FSe12= FSe12 FSe22= {(t.t)} FSe32= FSe13 Contents Foundations of Software Testing 2E Author: Aditya P.f)} FSe31= FSe13 Constraints common to Te1 and Te2 are removed.Step 5: Now construct FSe by removing from Fe any constraint that appeared in any of the two sets Te constructed earlier.f.f. Mathur 220 Copyright © 2013 Dorling Kindersley (India) Pvt.) .

t)} Note: Each constraint in StE makes E true and each constraint in SfE makes E false.f). Check it out! We are now done with the MI procedure.t. (f.t.f. Contents Foundations of Software Testing 2E Author: Aditya P.f.t.t).f.f).t.t). (t.t.t.f. (t.f.t.f).f).f.t.t).t.t)} Step 7: Now construct SE= StE ∪SfE SE={{(t. Ltd Step 6: Now construct SfE by selecting one constraint from each Fe .f. (t. (t. (t.f). Mathur 221 Copyright © 2013 Dorling Kindersley (India) Pvt.t. (f. (f.) SfE ={(f.t.t.MI procedure: Example (contd.f.

Ltd BOR-MI-CSET procedure . Mathur 222 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.The BOR-MI-CSET procedure takes a non-singular expression E as input and generates a constraint set that guarantees the detection of Boolean operator faults in the implementation of E. The BOR-MI-CSET procedure using the MI procedure described earlier. We illustrate it with an example. The entire procedure is described on page 195.

Mathur 223 . Contents Foundations of Software Testing 2E Author: Aditya P.BOR-MI-CSET: Example Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Consider a non-singular Boolean expression: E= a(bc+!bd) Mutually non-singular components of E: e1=a e2=bc+!bd We use the BOR-CSET procedure to generate the constraint set for e1 (singular component) and MI-CSET procedure for e2 (non-singular component).

Sfe1={f} Recall that Ste1 is true constraint set for e1 and Sfe1 is false constraint set for e1.) For component e1 we get: Ste1={t}.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd BOR-MI-CSET: Example (contd. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 224 .

Ltd Component e2 is a DNF expression. Mathur 225 .t).t).BOR-MI-CSET: Example (contd.t. We can write e2=u+v where u=bc and v=! bd. (f.t.t)} Contents Foundations of Software Testing 2E Author: Aditya P. As per Step 1 of the MI-CSET procedure we obtain: Tu={(t.f. Let us now apply the MI-CSET procedure to obtain the BOR constraint set for e2.t.f)} Tv={(f.) Copyright © 2013 Dorling Kindersley (India) Pvt. (t.

(f. Mathur 226 Copyright © 2013 Dorling Kindersley (India) Pvt.BOR-MI-CSET: Example (contd. t)} Next we apply Step 4 to u and v.f).) TSu=Tu TSv=Tv Ste2={(t. Can you think of other alternatives? u1=!bc u2=b!c v1=bd v2=!b!d Contents Foundations of Software Testing 2E Author: Aditya P.t. Ltd Applying Steps 2 and 3 to Tu and Tv we obtain: . t. We obtain the following complemented expressions from u and v: One possible alternative.

f)} Fv1={(t. (t.f.BOR-MI-CSET: Example (contd.t).f. (t.t). (f.f)} FSv1={(t.f)} Fu2=(t.t.f).f. (f.t.t. (f.) Fu1={(f.f.f).f.t)} FSv2={(f.f.f)} FSu2=(t.t).t.t.t)} Fv2={(f. Mathur 227 .t.f)} Copyright © 2013 Dorling Kindersley (India) Pvt.f.f)} Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Continuing with Step 4 we obtain: Next we apply Step 5 to the F constraint sets to obtain: FSu1={(f. (t.f.t).

f. (t. t).f). Contents Foundations of Software Testing 2E Author: Aditya P. (f. t. Mathur 228 . Ltd Applying Step 6 to the FS sets leads to the following Sfe2={(f.f).t. Combing the true and false constraint sets for e2 we get: Se2={(t.) Copyright © 2013 Dorling Kindersley (India) Pvt. (t.f.t)}.t.t.t)}.BOR-MI-CSET: Example (contd. {(f.f).

We now apply Step 2 of the BOR-CSET procedure to obtain the constraint set for the entire expression E. Sfe2={(f. Ltd Summary: from BOR-CSET procedure.t)} from MI-CSET procedure. (t.BOR-MI-CSET: Example (contd.t.t. t. Contents Foundations of Software Testing 2E Author: Aditya P.f). (f.f).) Ste1={(t)} Sfe1={(f)} Ste2={(t. Mathur 229 . t)} Copyright © 2013 Dorling Kindersley (India) Pvt.f.

(f)} b ∧ c !b d Apply MI-CSET Foundations of Software Testing 2E Author: Aditya P. (f.t. (t.f). (f.f). Mathur Contents 230 Copyright © 2013 Dorling Kindersley (India) Pvt.t.t.f.t.t.t)} N1 a ∧ {(t).f.) StN3=StN1 ⊗ StN22 AND node.t)} N2 ∨ {(t.BOR-MI-CSET: Example (contd.t. t).(t.t.t. Ltd Obtained by applying Step 2 of BOR-CSET to an .t.(t. (f.t).f). t.f. SfN3=(SfN1 × {t2})∪({t1} × SfN2) N3 ∧ {(t.f). (t.f.f).

Mathur 231 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Summary .Most requirements contain conditions under which functions are to be executed. Contents Foundations of Software Testing 2E Author: Aditya P. Predicate testing procedures covered are excellent means to generate tests to ensure that each condition is tested adequately.

Apply predicate testing Apply eq. Contents Foundations of Software Testing 2E Author: Aditya P.Summary (contd. action 2. BVA. and predicate testing if there are nested conditions. Mathur 232 . …action n. partitioning. Ltd Usually one would combine equivalence partitioning. boundary value analysis. and predicate testing procedures to generate tests for a requirement of the following type: if condition then action 1.) Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd Chapter 5 Test Generation from Finite State Models Updated: July 16. Mathur 233 . 2013 Foundations of Software Testing 2E Contents Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd Learning Objectives UIO method is not covered in these slides. Mathur 234 . Contents Foundations of Software Testing 2E Author: Aditya P. It is left for the students to read on their own (Section 5.8).§  What are Finite State Models? §  The W method for test generation §  The Wp method for test generation §  Automata theoretic versus control-flow based test generation Copyright © 2013 Dorling Kindersley (India) Pvt.

etc. transmission. steam boiler control. Mathur Contents 235 . nuclear plant protection systems. Alert: It will be a mistake to assume that the test generation methods described here are applicable only to protocol testing! Foundations of Software Testing 2E Author: Aditya P. Copyright © 2013 Dorling Kindersley (India) Pvt.g. etc). Ltd §  elevator designs. automobile components (locks. e.Where are these methods used? Conformance testing of communications protocols--this is where it all started. stepper motors.) §  Finite state machines are widely used in modeling of all kinds of systems. Generation of tests from FSM specifications assists in testing the conformance of implementations to the corresponding FSM model. §  Testing of any system/subsystem modeled as a finite state machine.

Ltd 5.2 Finite State Machines Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 236 .

Contents Foundations of Software Testing 2E Author: Aditya P. a network protocol could be modeled using an FSM. is an abstract representation of behavior exhibited by some systems. Mathur 237 Copyright © 2013 Dorling Kindersley (India) Pvt.A finite state machine. For example. abbreviated as FSM. Ltd What is a Finite State Machine? . An FSM is derived from application requirements.

Mathur 238 . and several types of computational requirements cannot be specified by an FSM. Real time requirements. Ltd What is a Finite State Machine? Not all aspects of an application’s requirements are specified by an FSM. Contents Foundations of Software Testing 2E Author: Aditya P. performance requirements.Copyright © 2013 Dorling Kindersley (India) Pvt.

The role assigned to an FSM depends on whether it is a part of the requirements specification or of the design specification. Mathur 239 . Ltd An FSM could serve any of two roles: as a specification of the required behavior and/ or as a design artifact according to which an application is to be implemented.0 design notation. Note that FSMs are a part of UML 2.Requirements or design specification? Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.

Modeling GUIs. network protocols. Mathur 240 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Where are FSMs used? . and many more. safety software modeling in nuclear plants. pacemakers. While the FSM’s considered in examples are abstract machines. Teller machines. WEB applications. they are abstractions of many real-life machines.

The term “state diagram” is often used to denote a graphical representation of an FSM or a statechart. Mathur 241 Copyright © 2013 Dorling Kindersley (India) Pvt.Note that FSMs are different from statecharts. Contents Foundations of Software Testing 2E Author: Aditya P. the reverse is not true. While FSMs can be modeled using statecharts. Ltd FSM and statcharts . Techniques for generating tests from FSMs are different from those for generating tests from statecharts.

Mathur 242 . where:. Q is a finite set states. X is a finite set of input symbols also known as the input alphabet. q0. Y is a finite set of output symbols also known as the output alphabet. δ: Q x X→ Q is a next-state or state transition function. Ltd An FSM (Mealy) is a 6-tuple: (X. q0 in Q is the initial state. O). and O: Q x X→ Y is an output function Contents Foundations of Software Testing 2E Author: Aditya P. Y.FSM (Mealy machine): Formal definition Copyright © 2013 Dorling Kindersley (India) Pvt. Q. δ.

X .Copyright © 2013 Dorling Kindersley (India) Pvt. Y. Ltd FSM (Moore machine): Formal definition An FSM (Moore) is a 7-tuple: (X. Q. and δ are the same as in FSM (Mealy) O: Q → Y is an output function F∈Q is the set of final or accepting or terminating states. Y. where:. O. Contents Foundations of Software Testing 2E Author: Aditya P. F). Mathur 243 . q0. δ. q0. Q.

H.Copyright © 2013 Dorling Kindersley (India) Pvt. F. Moore (1956 publication) Contents Foundations of Software Testing 2E Author: Aditya P. Mealy (1955 publication) Moore machines are due to E. Mathur 244 . Ltd FSM: Formal definition (contd.) Mealy machines are due to G.

Mathur 245 . Ltd Requirements FSM based Test inputs Application Observed behavior Contents Foundations of Software Testing 2E Author: Aditya P.Test generation from FSMs Our focus FSM Test generation algorithm Test generation for application Application Test inputs Blue: Generated Test driver data Pass/fail Test inputs Oracle Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd Many real-life devices have computers embedded in them. engine control being one example. Mathur 246 Copyright © 2013 Dorling Kindersley (India) Pvt. an . For example. An embedded system can be as simple as a child's musical keyboard or as complex as the flight controller in an aircraft. Another example is a computer inside a toy for processing inputs and generating audible and visual responses. Contents Foundations of Software Testing 2E Author: Aditya P. In any case.Embedded systems automobile has several embedded computers to perform various tasks. Such devices are also known as embedded systems. an embedded system contains one or more computers for processing inputs.

It is this behavior of an embedded system in response to inputs that is often modeled by a finite state machine (FSM). Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Specifying embedded systems . Mathur 247 Copyright © 2013 Dorling Kindersley (India) Pvt. While doing so. it moves from one state to another. The response of an embedded system to its inputs depends on its current state.An embedded computer often receives inputs from its environment and responds with appropriate actions.

Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 248 . (b) Lamp switch can be turned clockwise and counterclockwise.FSM: lamp example Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Simple three state lamp behavior: (a) Lamp switch can be turned clockwise.

and OUT actions. Contents Foundations of Software Testing 2E Author: Aditya P. (b) INIT: Initialize num. ADD. ADD: Add to num. INIT. OUT: Output num. Mathur 249 .FSM: Actions with state transitions Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Machine to convert a sequence of decimal digits to an integer: (a) Notice the ADD.

Mathur 250 . O). Q. Y. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd FSM: Formal definition An FSM is a quintuple: (X. where: X is a finite set of input symbols also known as the input alphabet. q0.Copyright © 2013 Dorling Kindersley (India) Pvt. Y is a finite set of output symbols also known as the output alphabet. δ. Q is a finite set states.

In some variants of FSM more than one state could be specified as an initial state. Contents Foundations of Software Testing 2E Author: Aditya P. sometimes it is convenient to add F⊆ Q as a set of final or accepting states while specifying an FSM. and O: Q x X→ Y is an output function. δ: Q x X→ Q is a next-state or state transition function.) Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 251 . Also. Ltd q0 in Q is the initial state.FSM: Formal definition (contd.

i is also known as the input portion of the edge and o its output portion. Each node is labeled with the state it represents. Mathur 252 Copyright © 2013 Dorling Kindersley (India) Pvt.A state diagram is a directed graph that contains nodes representing states and edges representing state transitions and output functions. Each directed edge in a state diagram connects two states. Ltd State diagram representation of FSM . Contents Foundations of Software Testing 2E Author: Aditya P. Each edge is labeled i/o where i denotes an input symbol that belongs to the input alphabet X and o denotes an output symbol that belongs to the output alphabet O.

Copyright © 2013 Dorling Kindersley (India) Pvt.2.2 Tabular representation Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 5. Mathur 253 .

The leftmost sub table is the output or the action sub-table. The rightmost sub-table is the next state sub-table. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Tabular representation of FSM . Mathur 254 Copyright © 2013 Dorling Kindersley (India) Pvt. The rows are labeled by the states of the FSM.A table is often used as an alternative to the state diagram to represent the state transition function δ and the output function O. The table consists of two sub-tables that consist of one or more columns each.

Mathur 255 . Ltd The table given below shows how to represent functions δ and O for the DIGDEC machine.Tabular representation of FSM: Example Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.

Mathur 256 .3 Properties of FSM Contents Foundations of Software Testing 2E Author: Aditya P.2.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 5.

Mathur 257 Copyright © 2013 Dorling Kindersley (India) Pvt. Strongly connected: An FSM M is considered strongly connected if for each pair of states (qi .Completely specified: An FSM M is said to be completely specified if from each state in M there exists a transition for each input symbol. qj) there exists an input sequence that takes M from state qi to state qj. Ltd Properties of FSM . Contents Foundations of Software Testing 2E Author: Aditya P.

be the states of machines M1 and M2. Let V denote a set of non-empty strings over the input alphabet X i. V⊆ X+. Y. O1) and M2=(X. T2. qi and qj are considered V-equivalent if O1(qi.V-equivalence: Let M1=(X. m10. s)=O2(qj. T1. Q2. Mathur 258 Copyright © 2013 Dorling Kindersley (India) Pvt. Q1. O2) be two FSMs. Y. s) for all s in V. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Properties of FSM: Equivalence .e. m20. respectively. Let qi and qj. i≠ j.

yield identical output sequences. Ltd Properties of FSM: Distinguishable .Stated differently. respectively. states qi and qj are considered V-equivalent if M1 and M2 . Contents Foundations of Software Testing 2E Author: Aditya P. r) for any set V. r)=O2(qj. If qi and qj are not equivalent then they are said to be distinguishable. machines M1 and M2 could be the same machine. This definition of equivalence also applies to states within a machine. Thus. Mathur 259 Copyright © 2013 Dorling Kindersley (India) Pvt. when excited in states qi and qj. States qi and qj are said to be equivalent if O1(qi.

Minimal machine: An FSM M is considered minimal if the number of states in M is less than or equal to any other FSM equivalent to M. Ltd Machine equivalence: Machines M1 and M2 are said to be equivalent if (a) for each . Machines that are not equivalent are considered distinguishable.Properties of FSM: Machine Equivalence state σ in M1 there exists a state σ ' in M2 such that σ and σ ' are equivalent and (b) for each state σ in M2 there exists a state σ ' in M1 such that σ and σ ' are equivalent. Mathur 260 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.

yield identical output sequences. Contents Foundations of Software Testing 2E Author: Aditya P. when excited by any input of length k. m20. Q1. Ltd Properties of FSM: k-equivalence . Q2. m10. O1) and M2=(X.k-equivalence: Let M1=(X. Y. Y. T2. O2) be two FSMs. T1. Mathur 261 Copyright © 2013 Dorling Kindersley (India) Pvt. States qiε Q1 and qjε Q2 are considered k-equivalent if.

Contents Foundations of Software Testing 2E Author: Aditya P. Ltd States that are not k-equivalent are considered k-distinguishable. Mathur 262 .) Copyright © 2013 Dorling Kindersley (India) Pvt. M1 and M2 may be the same machines implying that kdistinguishability applies to any pair of states of an FSM.Properties of FSM: k-equivalence (contd. If M1 and M2 are not kdistinguishable then they are said to be k-equivalent. It is also easy to see that if two states are k-distinguishable for any k>0 then they are also distinguishable for any n≥ k. Once again.

Ltd Example: Completely specified machine Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 263 .Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 264 . Ltd 5.Copyright © 2013 Dorling Kindersley (India) Pvt.4 A fault model Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd Faults in implementation . What faults are targeted by the tests generated using an FSM? Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 265 Copyright © 2013 Dorling Kindersley (India) Pvt. Hence tests generated from an FSM target faults related to the FSM itself.An FSM serves to specify the correct requirement or design of an application.

Mathur 266 . Ltd a/1 Operation error a/1 Transfer error Contents Foundations of Software Testing 2E Author: Aditya P.Fault model a/0 q0 q0 a/1 b/1 q0 a/1 b/1 a/1 b/1 q1 q1 q1 b/0 b/0 b/0 Correct design Copyright © 2013 Dorling Kindersley (India) Pvt.

) q1 b/0 Extra state error Missing state error Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Fault model (contd.a/1 b/1 a/0 q0 q0 a/1 q2 a/1 b/0 Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 267 .

Mathur 268 .6 The W-method Contents Foundations of Software Testing 2E Author: Aditya P.5 Characterization set 5. Ltd 5.Copyright © 2013 Dorling Kindersley (India) Pvt.

Completely specified: An FSM M is said to be completely specified if from each state in M there exists a transition for each input symbol. Mathur 269 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Assumptions for test generation . Contents Foundations of Software Testing 2E Author: Aditya P.Minimality: An FSM M is considered minimal if the number of states in M is less than or equal to any other FSM equivalent to M.

Step 5: Desired test set=P. Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P from the testing tree. Mathur 270 Copyright © 2013 Dorling Kindersley (India) Pvt. Step 4: Construct set Z from W and m.Step 1: Estimate the maximum number of states (m) in the correct implementation of the given FSM M. Step 2: Construct the characterization set W for M.Z Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Chow’s (W) method .

let m=|Q|. In the absence of any such knowledge. Mathur 271 . Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Step 1: Estimation of m This is based on a knowledge of the implementation.

δ. Given states qi and qj in Q. q1. Each input sequence in W is of finite length. Mathur 272 . Ltd Let M=(X. s) Contents Foundations of Software Testing 2E Author: Aditya P. W contains a string s such that: O(qi. s)≠O(qj. Q. W is a finite set of input sequences that distinguish the behavior of any pair of states in M. O) be a minimal and complete FSM.Step 2: Construction of the W-set Copyright © 2013 Dorling Kindersley (India) Pvt. Y.

q1)=1101 O(baaa.q2) Contents Foundations of Software Testing 2E Author: Aditya P. baaa distinguishes state q1 from q2 as O(baaa.aa.q1) ≠ O(baaa. Ltd Example of a W-set W={baaa. Mathur 273 .aaa} O(baaa.q2)=1100 Thus.Copyright © 2013 Dorling Kindersley (India) Pvt.

Step 2: Traverse the k-equivalence partitions in reverse order to obtain distinguishing sequence for each pair of states. …Pm. Mathur 274 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Steps in the construction of W-set . P2. m>0.Step 1: Construct a sequence of k-equivalence partitions of Q denoted as P1.

Ltd What is a k-equivalence partition of Q? . Σk2 … Σkn such that ∪ni=1 Σki =Q States in Σki are k-equivalent. Contents Foundations of Software Testing 2E Author: Aditya P. then u and v are k-distinguishable. is a collection of n finite sets Σk1. If state u is in Σki and v in Σkj for i≠j.A k-equivalence partition of Q. denoted as Pk. Mathur 275 Copyright © 2013 Dorling Kindersley (India) Pvt.

Current state Output Next state a b a b q1 0 1 q1 q4 q2 0 1 q1 q5 q3 0 1 q5 q1 q4 1 1 q3 q4 q5 1 1 q2 q5 Contents Foundations of Software Testing 2E Author: Aditya P.How to construct a k-equivalence partition? Copyright © 2013 Dorling Kindersley (India) Pvt. start with a tabular representation of M. Ltd Given an FSM M. construct a 1-equivalence partition. Mathur 276 .

Ltd of Σ1={q1. This gives us 1-partition P1 consisting Σ 1 2 Current state Output Copyright © 2013 Dorling Kindersley (India) Pvt. Next state a b a b q1 0 1 q1 q4 q2 0 1 q1 q5 q3 0 1 q5 q1 q4 1 1 q3 q4 q5 1 1 q2 q5 Contents Foundations of Software Testing 2E Author: Aditya P.Construct 1-equivalence partition Group states identical in their Output entries. q2. Mathur 277 . q5}. q3} and Σ2 ={q4.

Replace a state entry qi by qij where j . Remove the output columns. Mathur 278 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Rewrite P1 table.Construct 2-equivalence partition: Rewrite P1 table is the group number in which lies state qi. Σ 1 2 Current state Next state a b q1 q11 q42 q2 q11 q52 q3 q52 q11 q4 q31 q42 q5 q21 q52 P1 Table Group number Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd Group all entries with identical second subscripts under the next state column. Mathur 279 Copyright © 2013 Dorling Kindersley (India) Pvt.Construct 2-equivalence partition: Construct P2 table gives us the P2 table. This . Note the change in second subscripts. Σ Current state Next state a b q1 q11 q43 q2 q11 q53 2 q3 q53 q11 3 q4 q32 q43 q5 q21 q53 1 P2 Table Contents Foundations of Software Testing 2E Author: Aditya P.

Mathur 280 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Group all entries with identical second subscripts under the next state column.Construct 3-equivalence partition: Construct P3 table gives us the P3 table. This . Note the change in second subscripts. Σ Current state Next state a b q1 q11 q43 q2 q11 q54 2 q3 q54 q11 3 q4 q32 q43 4 q5 q21 q54 1 P3 Table Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd Continuing with regrouping and relabeling. we finally arrive at P4 table. . Mathur 281 Copyright © 2013 Dorling Kindersley (India) Pvt.Construct 4-equivalence partition: Construct P4 table Σ Current state P4 Table Next state a b 1 q1 q11 q44 2 q2 q11 q55 3 q3 q55 q11 4 q4 q33 q44 5 q5 q22 q55 Contents Foundations of Software Testing 2E Author: Aditya P.

The next step is to obtain the distinguishing strings for each state. and the machine is minimal. When the process converges. Ltd k-equivalence partition: Convergence The process is guaranteed to converge.Copyright © 2013 Dorling Kindersley (India) Pvt. each state will be in a separate group. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 282 .

Copyright © 2013 Dorling Kindersley (India) Pvt. Find tables Pi and Pi+1 such that (q1. This symbol is b. Mathur 283 . Initialize z=ε.b. Ltd Finding distinguishing sequences: Example Let us find a distinguishing sequence for states q1 and q2. Contents Foundations of Software Testing 2E Author: Aditya P. Find the input symbol that distinguishes q1 and q2 in table P3. We update z to z. Hence z now becomes b. We get P3 and P4. q2) are in the same group in Pi and different groups in Pi+1.

respectively. q3 and q2. The next states for states q4 and q5 on symbol a are. respectively. Update z which now becomes ba. Ltd Finding the distinguishing sequences: Example (contd. q4 and q5. We update z to baa. Contents Foundations of Software Testing 2E Author: Aditya P. Let us select a as the distinguishing symbol. We move to the P2 table and find the input symbol that distinguishes q4 and q5.The next states for q1 and q2 on b are. Mathur 284 Copyright © 2013 Dorling Kindersley (India) Pvt. These two states are distinguished in P1 by a and b. Let us select a.) .

) .baaa). Check that o(q1. Mathur 285 Copyright © 2013 Dorling Kindersley (India) Pvt.baaa)≠o(q2. respectively. q1 and q5. Moving to the original state transition table we obtain a as the distinguishing symbol for q1 and q5 We update z to baaa. This is the farthest we can go backwards through the various tables.The next states for q3 and q2 on a are. Ltd Finding the distinguishing sequences: Example (contd. baaa is the desired distinguishing sequence for states q1 and q2. Contents Foundations of Software Testing 2E Author: Aditya P.

aa. we can find the distinguishing sequence for each pair of states. Ltd Finding the distinguishing sequences: Example (contd.Copyright © 2013 Dorling Kindersley (India) Pvt.) Using the procedure analogous to the one used for q1 and q2. aaa. baaa} Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 286 . W={a. This leads us to the following characterization set for our FSM.

Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P Next (a) from the testing tree. Step 2: Construct the characterization set W for M. Mathur 287 Copyright © 2013 Dorling Kindersley (India) Pvt. Step 4: Construct set Z from W and m.Z Contents Foundations of Software Testing 2E Author: Aditya P. Step 5: Desired test set=P. Ltd Chow’s method: where are we? .Step 1: Estimate the maximum number of states (m) in the correct implementation Done of the given FSM M.

is the root of the testing tree. Contents Foundations of Software Testing 2E Author: Aditya P. then n is a leaf node and is not expanded any further. If n appears at any level from 1 through k . the initial state. This branch is labeled as x. Ltd A testing tree of an FSM is a tree rooted at the initial state. x)=m for x∈ X . Here is how we construct the testing tree. The (k+1)th level is built as follows. Suppose that the testing tree has been constructed until level k . Mathur 288 Copyright © 2013 Dorling Kindersley (India) Pvt. It contains at least one . Select a node n at level k. State q0.Step 3: (a) Construct the testing tree for M path from the initial state to the remaining states in the FSM. If n is not a leaf node then we expand it by adding a branch from node n to a new node m if δ(n. This step is repeated for all nodes at level k.

q4 can be expanded. initial state is the root. Contents Foundations of Software Testing 2E Author: Aditya P. . Mathur 289 Copyright © 2013 Dorling Kindersley (India) Pvt. No further expansion possible . Ltd Start here.Example: Construct the testing tree for M q1 becomes leaf. . M .

Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P Next. Step 2: Construct the characterization set W for M. Mathur 290 Copyright © 2013 Dorling Kindersley (India) Pvt.Z Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Chow’s method: where are we? .Step 1: Estimate the maximum number of states (m) in the correct implementation Done of the given FSM M. (b) from the testing tree. Step 5: Desired test set=P. Step 4: Construct set Z from W and m.

bb. ba. baa. a. baaab. in the testing tree.Step 3: (b) Find the transition cover set from the testing tree root. baaa. P={ε. Concatenation of the labels along the edges of a sub-path is a string that belongs to P. b. bab. The empty string (ε) also belongs to P. Mathur 291 Copyright © 2013 Dorling Kindersley (India) Pvt. baab. starting at the . Ltd A transition cover set P is a set of all strings representing sub-paths. baaaa} Contents Foundations of Software Testing 2E Author: Aditya P.

Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P Done from the testing tree. Step 2: Construct the characterization set W for M. Ltd Chow’s method: where are we? .Z Contents Foundations of Software Testing 2E Author: Aditya P. Next Step 5: Desired test set=P. Mathur 292 Copyright © 2013 Dorling Kindersley (India) Pvt.Step 1: Estimate the maximum number of states (m) in the correct implementation Done of the given FSM M. Step 4: Construct set Z from W and m.

we have: Z = X0. aaa.W=W For X={a. W={a. b}. aaa. m=6 Z = W ∪ X1. aa. aaa. Ltd Given that X is the input alphabet and W the characterization set.{a. aa.Step 4: Construct set Z from W and m Copyright © 2013 Dorling Kindersley (India) Pvt.W ∪ X1. aa. aaa. baa.W For m=n. baaa. baaaa.W ={a. ba. Xm-1-n. baaa} ∪ {a.. baaa}.W ∪ …. aa. Mathur 293 . aaa. baaa. we get Z = X0. aaaa. baaa} ={a. bbaaa} Contents Foundations of Software Testing 2E Author: Aditya P. aa.W ∪ Xm-n. b}.

Step 1: Estimate the maximum number of states (m) in the correct implementation Done of the given FSM M. Step 4: Construct set Z from W and m.Z Done Next Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Chow’s method: where are we? . Step 5: Desired test set=P. Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P Done from the testing tree. Step 2: Construct the characterization set W for M. Mathur 294 Copyright © 2013 Dorling Kindersley (India) Pvt.

  Execute the application and check if the response matches.  Generate test cases for the application. 3.  Find the expected response to each element of T.Step 5: Desired test set=P. Ltd The test inputs based on the given FSM M can now be derived as: T=P. Mathur Contents 295 .Z Do the following to test the implementation: 1. Foundations of Software Testing 2E Author: Aditya P. 2. Note that even though the application is modeled by M. there might be variables to be set before it can be exercised with elements of T.Z Copyright © 2013 Dorling Kindersley (India) Pvt. Reset the application to the initial state after each test.

Ltd Correct design t1=baaaaaa t2=baaba M1(t1)=1101001 M2(t2)=11001 M1 Foundations of Software Testing 2E Contents M2 Author: Aditya P.Example 1: Testing an erroneous application Error revealing M(t1)=1101001 M M(t2)=11011 test cases Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 296 .

N=5. Author: Aditya P.M1 M2 t1=baaba M(t1)=11011 M1(t1)=11001 t2=baaa M(t2)=1101 M2(t2)=1100 Foundations of Software Testing 2E Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur Contents 297 . m=6. Ltd Example 2: Extra state.

Mathur 298 . Then.Error detection process: in-class discussion Given m=n. r Copyright © 2013 Dorling Kindersley (India) Pvt. s=as’ takes it from qi to state qj or qj’. Contents Foundations of Software Testing 2E Author: Aditya P. each test case t is of the form r. Ltd moves the application from initial state q0 to state qj.s where r is in P and s in W.

Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 299 .7 The Partial W method Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 5.

Tests are generated from minimal. Size of tests generated is generally smaller than that generated using the W-method. and connected FSM. Phase 2: Generate additional tests using a subset of the transition cover set and state identification sets. complete. What is a state cover set? A state identification set? Contents Foundations of Software Testing 2E Author: Aditya P. Ltd The partial W (Wp) method . Test generation process is divided into two phases: Phase 1: Generate a test set using the state cover set (S) and the characterization set (W). Mathur 300 Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 301 Copyright © 2013 Dorling Kindersley (India) Pvt. there is a string in S that takes M from its initial state to qi. ba. a state cover set S is a finite non-empty set of . b. Contents Foundations of Software Testing 2E Author: Aditya P. baaa} S is always a subset of the transition cover set P. Ltd Given FSM M with input alphabet X. Also.State cover set strings over X* such that for each state qi in Q. S is not necessarily unique. S={ε. baa.

s)≠ O(qj. there is a string in Wi that distinguishes qi from qj. [Wi is minimal. for 1≤j≤ n . j≠ i .] Contents Foundations of Software Testing 2E Author: Aditya P.] (b) O(qi.Given an FSM M with Q as the set of states. s) . Ltd State identification set . s∈ Wi [For each state other than qi. Mathur 302 Copyright © 2013 Dorling Kindersley (India) Pvt. 1≤ i≤n [Identification set is a subset of W.] (c) No subset of Wi satisfies property (b). an identification set for state qi∈Q is denoted by Wi and has the following properties: (a) Wi⊆ W .

Ltd State identification set: Example . a} W3={a aa} W4=W5={a.x) 1 2 baaa 1 0 3 aa 0 1 4 a 0 1 5 a 0 1 3 aa 0 1 4 a 0 1 5 a 0 1 4 a 0 1 5 a 0 1 5 aaa 1 0 2 3 W1=W2={baaa. aa. Mathur 303 Copyright © 2013 Dorling Kindersley (India) Pvt. aaa} Foundations of Software Testing 2E 4 Contents Author: Aditya P.Last element of the output string Si Sj X o(Si.x) o(Sj.

P. aaa. W4. W2. aaa} W={a. baaab. baa. aa. Wi. a. W5} Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 304 . baaa. W. a} W3={a aa} W4=W5={a. baab. ba. bb. b. baaa} P={ε. baa. W3.W S={ε.Copyright © 2013 Dorling Kindersley (India) Pvt. b. bab. ba. aa. baaa} W={W1. Ltd Wp method: Example: Step 1: Compute S. baaaa} W1=W2={baaa.

ba.Copyright © 2013 Dorling Kindersley (India) Pvt. baaa}. baaa} Elements of T1 ensure that the each state of the FSM is covered and distinguished from the remaining states. W={ε. aaa. baa.{a. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 305 . aa. Ltd Wp method: Example: Step 2: Compute T1 [m=n] T1=S. b.

bab. b. Copyright © 2013 Dorling Kindersley (India) Pvt.R=P-S={ε. baaa. baa. baab. baaaa}-{ε. Ltd Wp method: Example: Step 3: Compute R and δ [m=n] ba. ba. baaab. ri2. baa. baaa} ={a. baaab. m)=qij . Mathur 306 . baaaa} Let each element of R be denoted as ri1. a. bab.…rik. where m∈X (the alphabet) Contents Foundations of Software Testing 2E Author: Aditya P. bb. b. baab. δ(rik. bb.

W4 ) ∪ ({bab}. Ltd T2=R⊗W=∪k(j=1) (rij}. bb)=q4 δ(q1. a)=q1 δ(q1. Wij . δ(q1. baab)=q5 δ(q1. bbaaa} ∪ {baba. aa} ∪ {bba.W5 ) ∪ ({baaaa}.Wp method: Example: Step 4: Compute T2 [m=n] δ(q1. where Wij is the identification set for state qij. baaaaa} Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 307 .W5 ) ∪ {baaab}. W1 ) ={abaaa. baabaaa} ∪ {baaaba.W5 ) ∪ ({baab}. W1 )∪ ({bb}. baaaa)=q1 Copyright © 2013 Dorling Kindersley (India) Pvt. baaab)=q5 δ(q1. baaabaaa} ∪ {baaaabaaa. babaaa} ∪ {baaba. bab)=q5 T2=({a}. aaa. baaaaaa.

Ltd Wp method: Example: Savings Test set size using the W method= 44 Test set size using the Wp method= 34 (20 from T1+14 from T2) Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 308 .

Tests from T1 are applied in phase 1. they do not ensure all transition coverage. Mathur 309 . Tests from T2 are applied in phase 2. Also. While tests from phase 1 ensure state coverage. even when tests from phase cover all transitions. Ltd Testing proceeds in two phases.Testing using the Wp method Copyright © 2013 Dorling Kindersley (India) Pvt. they do not apply the state identification sets and hence not all transfer errors are guaranteed to be revealed by these tests. Contents Foundations of Software Testing 2E Author: Aditya P.

Copyright © 2013 Dorling Kindersley (India) Pvt. where X[m-n] is the set union of Xi . X[m-n]. X[m-n] ⊗W Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Wp method: Both sets T1 and T2 are computed a bit differently. as follows: T1=S. 1≤i≤ (m-n) T2= T2=R. Mathur 310 .

8 The UIO sequence method [See the text] Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 311 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 5.

Ltd 5. Mathur 312 .9 Automata theoretic versus control flow based techniques Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 313 Copyright © 2013 Dorling Kindersley (India) Pvt. many books on software testing mention control-theoretic techniques for test generation. Contents Foundations of Software Testing 2E Author: Aditya P. Let us understand the difference between the two types of techniques and their fault detection abilities. Ltd Automata-theoretic vs.The W and the Wp methods are considered automata-theoretic methods for test generation. Control theoretic techniques . In contrast.

Transition cover: A test set T is considered adequate with respect to the branch/ transition cover criterion for an FSM M if the execution of M against each element of T causes each transition in M to be taken at least once Contents Foundations of Software Testing 2E Author: Aditya P.Control theoretic techniques Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 314 . Ltd State cover: A test set T is considered adequate with respect to the state cover criterion for an FSM M if the execution of M against each element of T causes each state in M to be visited at least once.

b) and qi. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Control theoretic techniques (contd. qk are states in M.Copyright © 2013 Dorling Kindersley (India) Pvt.) Switch cover: A test set T is considered adequate with respect to the 1-switch cover criterion for an FSM M if the execution of M against each element of T causes each pair of transitions (tr1. qj. Mathur 315 . where for some input substring ab tr1: qi=δ(qj. a) and tr_2: qk= δ(qi. tr2) in M to be taken at least once.

Mathur 316 Copyright © 2013 Dorling Kindersley (India) Pvt.Boundary interior cover: A test set T is considered adequate with respect to the boundary-interior cover criterion for an FSM M if the execution of M against each element of T causes each loop (a self-transition) across states to be traversed zero times and at least once. Ltd Control theoretic techniques (contd. Contents Foundations of Software Testing 2E Author: Aditya P. Exiting the loop upon arrival covers the ``boundary" condition and entering it and traversing the loop at least once covers the ``interior" condition.) .

Both machines generate the same output which is 0111. a correct one (M1) and one with a transfer error . t=abba covers all states but does not not reveal the error.Control theoretic technique: Example 1 (M1’). Will the tests generated by the W method reveal this error? Check it out! Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Consider the following machines. Mathur 317 Copyright © 2013 Dorling Kindersley (India) Pvt.

Consider the test set: {bb. such as (tr1. tr6. aabb. abbaab}. a correct one (M2) and one with a transfer error . aaba. Mathur 318 Copyright © 2013 Dorling Kindersley (India) Pvt. Does it cover all branches? Does it reveal the error? Are the states in M2 1-distinguishable? Contents Foundations of Software Testing 2E Author: Aditya P. tr5). (tr1. tr3). baab. There are 12 branch pairs. Ltd Consider the following machines.Control theoretic technique: Example 2 (M2’). tr2).

Ltd Consider the following machines. Mathur 319 . T2 causes each loop to be traversed once. a correct one (M3) and one with a transfer error not traversed. Consider T={t1: aab.Control theoretic technique: Example 3 (M3’). t2: abaab}. Is the error revealed by T? Contents Foundations of Software Testing 2E Author: Aditya P. T1 causes each state to be entered but loop Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 320 Copyright © 2013 Dorling Kindersley (India) Pvt. Tests so generated are guaranteed to detect all operation errors. transfer errors. and minimal. What happens if it is not? Contents Foundations of Software Testing 2E Author: Aditya P. connected. Ltd Behavior of a large variety of applications can be modeled using finite state . and missing/extra state errors in the implementation given that the FSM representing the implementation is complete.Summary machines (FSM). GUIs can also be modeled using FSMs The W and the Wp methods are automata theoretic methods to generate tests from a given FSM model.

) Copyright © 2013 Dorling Kindersley (India) Pvt. The size of tests sets generated by the W method is larger than generated by the Wp method while their fault detection effectiveness are the same. Contents Foundations of Software Testing 2E Author: Aditya P. boundary-interior. and n-switch cover.Summary (contd. that are often described in books on software testing. state cover. Control-theoretic techniques. Ltd Automata theoretic techniques generate tests superior in their fault detection ability than their control-theoretic counterparts. include branch cover. Mathur 321 .

Mathur 322 . 2013 Foundations of Software Testing 2E Contents Author: Aditya P. Ltd Chapter 6 Test Generation: Combinatorial Designs Updated: July 16.Copyright © 2013 Dorling Kindersley (India) Pvt.

covering arrays and mixed-level covering arrays? §  How to generate mixed-level covering arrays and test configurations from them? Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 323 .§  What are test configurations? How do they differ from test sets? §  Why combinatorial design? §  What are Latin squares and mutually orthogonal Latin squares (MOLS)? §  How does one generate test configurations from MOLS? §  What are orthogonal arrays. Ltd Learning Objectives Contents Foundations of Software Testing 2E Author: Aditya P.

Mathur 324 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 6.1.1. Test configuration and test set Contents Foundations of Software Testing 2E Author: Aditya P.

lead to a variety of environments. §  An environment is characterized by combination of hardware and software. Mathur 325 Copyright © 2013 Dorling Kindersley (India) Pvt. network connection. and hardware platform. Contents Foundations of Software Testing 2E Author: Aditya P. Combinations of factors such as the operating system. known as a test configuration. §  Each environment corresponds to a given set of values for each factor.§  Software applications are often designed to work in a variety of environments. Ltd Test configuration .

Dial-up connection. or environments. is one possible configuration. Mathur 326 Copyright © 2013 Dorling Kindersley (India) Pvt. the application must be tested under as many test configurations. Ltd Test configuration: Example . Contents Foundations of Software Testing 2E Author: Aditya P. §  To ensure high reliability across the intended environments. and a PC with 512MB of main memory. The number of such test configurations could be exorbitantly large making it impossible to test the application exhaustively. as possible.§  Windows XP. can be combined to create several test configurations for a printer. §  Different versions of operating systems and printer drivers.

a test set is a collection of test cases. Ltd Test configuration and test set .§  While a test configuration is a combination of factors corresponding to hardware and software within which an application is to operate. §  Techniques we shall learn are useful in deriving test configurations as well as test sets. Each test case consists of input values and expected output. Mathur 327 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.

each test run of a program often requires at least one value for each variable. §  For example.§  While testing a program with one or more input variables. Contents Foundations of Software Testing 2E Author: Aditya P. one corresponding to x and the other to y. a program to find the greatest common divisor of two integers x and y requires two values. Mathur 328 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Motivation .

Ltd Motivation [2] While equivalence partitioning discussed earlier offers a set of guidelines to design test cases. Mathur 329 . Contents Foundations of Software Testing 2E Author: Aditya P. (b) It lacks guidelines on how to select inputs from various sub-domains in the partition.Copyright © 2013 Dorling Kindersley (India) Pvt. it suffers from two shortcomings: (a) It raises the possibility of a large number of sub-domains in the partition.

especially when using uni-dimensional equivalence partitioning. Such a selection procedure. Contents Foundations of Software Testing 2E Author: Aditya P. does not account for the possibility of faults in the program under test that arise due to specific interactions amongst values of different input variables. and especially so when multidimensional partitioning is used. Ltd Motivation [3] . one selects at random a value from each of the subdomains. Mathur 330 Copyright © 2013 Dorling Kindersley (India) Pvt.The number of sub-domains in a partition of the input domain increases in direct proportion to the number and type of input variables. Once a partition is determined.

Mathur 331 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Motivation [4] . is large and complex.While boundary values analysis leads to the selection of test cases that test a program at the boundaries of the input domain. Contents Foundations of Software Testing 2E Author: Aditya P. We will learn several techniques for generating test configurations or test sets that are small even when the set of possible configurations or the input domain and the number of sub-domains in its partition. other interactions in the input domain might remain untested.

Modeling the input and configuration spaces Contents Foundations of Software Testing 2E Author: Aditya P.1.Copyright © 2013 Dorling Kindersley (India) Pvt.2. Ltd 6. Mathur 332 .

Mathur 333 Copyright © 2013 Dorling Kindersley (India) Pvt.The input space of a program P consists of k-tuples of values that could be input to P during execution. Ltd Modeling: Input and configuration space [1] . Consider program P that takes two integers x>0 and y>0 as inputs. Contents Foundations of Software Testing 2E Author: Aditya P. The input space of P is the set of all pairs of positive non-zero integers. The configuration space of P consists of all possible settings of the environment variables under which P could be used.

Contents Foundations of Software Testing 2E Author: Aditya P. Y a browser. Mathur 334 Copyright © 2013 Dorling Kindersley (India) Pvt. through the Netscape or Safari browsers. Y. and Z a local or a networked printer. and must be able to print to a local or a networked printer. Z) where X represents an operating system. The configuration space of P consists of triples (X. Ltd Modeling: Input and configuration space [2] .Now suppose that this program is intended to be executed under the Windows and the MacOS operating system.

We refer to the inputs as factors. 1≤ i ≤ n values. Contents Foundations of Software Testing 2E Author: Aditya P. Each value assignable to a factor is known as a level.Xn. |F| refers to the number of levels for factor F. The inputs are also referred to as test parameters or as values. Ltd Factors and levels . X2.Consider a program P that takes n inputs corresponding to variables X1. . Let us assume that each factor may be set at any one from a total of ci. Mathur 335 Copyright © 2013 Dorling Kindersley (India) Pvt..

Thus. d). f). Mathur 336 Copyright © 2013 Dorling Kindersley (India) Pvt. f). This leads to a total of 32=9 factor combinations. respectively. (a. d). c} and {d. Ltd Factor combinations . e. f}. e). b. (c. (b. (c. f). suppose that program P has two input variables X and Y. For example. is known as a factor combination. e). Contents Foundations of Software Testing 2E Author: Aditya P. d). Let us say that during an execution of P. e). (a.A set of values. X and Y may each assume a value from the set {a. we have 2 factors and 3 levels for each factor. one for each factor. and (c. (b. namely (a. (b.

Mathur 337 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Factor combinations: Too large? . For many programs. Contents Foundations of Software Testing 2E Author: Aditya P. for k factors with each factor assuming a value from a set of n values. Executing a billion tests might be impractical for many software applications. the total number of tests is 415 ~109. the total number of factor combinations is nk. Suppose now that each factor combination yields one test case. the number of tests generated for exhaustive testing could be exorbitantly large. For example. if a program has 15 factors with 4 levels each.In general.

T. Ltd Example: Pizza Delivery Service (PDS) [1] . and P. checks for their validity. Delivery address and a home phone number. Toppings list. Let us denote these four factors by S. and schedules Pizza for delivery. respectively. A.A PDS takes orders online. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 338 Copyright © 2013 Dorling Kindersley (India) Pvt. A customer is required to specify the following four items as part of the online order: Pizza size.

and Small. and the zip code. The delivery address consists of customer name. There is a list of 6 toppings from which to select. Medium.Suppose now that there are three varieties for size: Large. In addition. city. one line of address. Ltd Pizza Delivery Service (PDS): Specs . Mathur 339 Copyright © 2013 Dorling Kindersley (India) Pvt. The phone number is a numeric string possibly containing the dash (``--") separator. the customer can customize the toppings. Contents Foundations of Software Testing 2E Author: Aditya P.

Suppose we consider 6+1=7 levels for Toppings. Number of combinations= 24+5x23+23+5x22=84. Different types of values for Address and Phone number will further increase the combinations Contents Foundations of Software Testing 2E Author: Aditya P. Ltd PDS: Input space model .The total number of factor combinations is 24+23=24. Mathur 340 Copyright © 2013 Dorling Kindersley (India) Pvt.

Edit.Example: Testing a GUI Copyright © 2013 Dorling Kindersley (India) Pvt. Thus. we have a total 43=64 factor combinations. Each of these three factors can be set to any of four levels. Mathur 341 . Ltd The Graphical User Interface of application T consists of three menus labeled File. Contents Foundations of Software Testing 2E Author: Aditya P. and Format. We have three factors in T.

9x109 combinations. sort [-cmu] [-ooutput] [-Tdirectory] [-y [ kmem]] [-zrecsz] [-dfiMnr] [-b] [ tchar] [kkeydef] [+pos1[-pos2]] [file. The command line for sort is given below.1 of the book lead to a total of approximately 1. Ltd The sort utility has several options and makes an interesting example for the identification of factors and levels. Mathur 342 .Example: The UNIX sort utility Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P...] We have identified a total of 20 factors for the sort command. The levels listed in Table 11.

OS. Here we consider a combination of hardware. Ltd There is often a need to test a web application on different platforms to ensure that any claim such as ``Application X can be used under Windows and Mac OS X” are valid. Contents Foundations of Software Testing 2E Author: Aditya P. hardware. OS.e. Let X denote a Web application to be tested for compatibility. Mathur 343 . it is easy to obtain three factors. i. operating system. Given that we want X to work on a variety of hardware. and a browser as a platform. and browser combinations.Example: Compatibility testing Copyright © 2013 Dorling Kindersley (India) Pvt. and browser.

Mathur 344 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Compatibility testing: Factor levels Contents Foundations of Software Testing 2E Author: Aditya P.

Contents Foundations of Software Testing 2E Author: Aditya P. Ltd There are 75 factor combinations. Similarly. we assume that this is not the case for testing application X. some of these combinations are infeasible. . the Safari browser is used on Apple computers and not on the PC in the Dell Series. Mathur 345 Copyright © 2013 Dorling Kindersley (India) Pvt. While various editions of the Windows OS can be used on an Apple computer using an OS bridge such as the Virtual PC. However.2 is an OS for the Apple computers and not for the Dell Dimension series PCs. Mac OS10.Compatibility testing: Combinations For example.

Thus. Note that there is a large number of hardware configurations under the Dell Dimension Series. processor speeds. Pentium versus Athelon. and several others. memory sizes. These configurations are obtained by selecting from a variety of processor types. e. in all we are left with 35 platforms on which to test X. Mathur 346 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Compatibility testing: Reduced combinations .The discussion above leads to a total of 40 infeasible factor combinations corresponding to the hardware-OS combination and the hardware-browser combination.g. Contents Foundations of Software Testing 2E Author: Aditya P.

and hence the time to test.While testing against all configurations will lead to more thorough testing of application X. Contents Foundations of Software Testing 2E Author: Aditya P. it will also increase the number of factor combinations. Mathur 347 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Compatibility testing: Reduced combinations-2 .

Combinatorial test design process Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 348 .Copyright © 2013 Dorling Kindersley (India) Pvt.2. Ltd 6.

Ltd Combinatorial test design process . Mathur 349 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.Modeling of input space or the environment is not exclusive and one might apply either one or both depending on the application under test.

Mathur 350 Copyright © 2013 Dorling Kindersley (India) Pvt.Combinatorial test design process: steps terms of factors and their respective levels. Contents Foundations of Software Testing 2E Author: Aditya P. Such an object is also known as a factor covering design. Steps 2 and 3 can be automated. Step 3: The combinatorial object generated is used to design a test set or a test configuration as the requirement might be. Ltd Step 1: Model the input space and/or the configuration space. The model is expressed in . Step 2: The model is input to a combinatorial design procedure to generate a combinatorial object which is simply an array of factors and levels.

” Two sample test cases are: t1: sort -o afile bfile t2: sort -o cfile dfile Is one of the above tests sufficient? Foundations of Software Testing 2E Author: Aditya P. Mathur 351 Contents Copyright © 2013 Dorling Kindersley (India) Pvt. For example.Combinatorial test design process: test inputs many test inputs. consider the combination in which all factors are set to ``Unused" except the -o option which is set to ``Valid File" and the file option that is set to ``Exists.1 can be used to generate . Ltd Each combination obtained from the levels listed in Table 6.

Contents Foundations of Software Testing 2E Author: Aditya P. Further. This sequence too must be determined by the tester. For each test . Mathur 352 Copyright © 2013 Dorling Kindersley (India) Pvt. The sequencing of tests generated by most test generation techniques must be determined by the tester and is not a unique characteristic of test generated in combinatorial testing. Ltd Combination of factor levels is used to generate one or more test cases. the sequence in which inputs are to be applied to the program under test must be determined by the tester.Combinatorial test design process: summary case. the factor combinations do not indicate in any way the sequence in which the generated tests are to be applied to the program under test.

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 6.3. Fault model Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 353 .

We say that an interaction fault is triggered when a certain combination of t≥1 input values causes the program containing the fault to enter an invalid state. Contents Foundations of Software Testing 2E Author: Aditya P. this invalid state must propagate to a point in the program execution where it is observable and hence is said to reveal the fault. Of course. Mathur 354 Copyright © 2013 Dorling Kindersley (India) Pvt.Faults aimed at by the combinatorial design techniques are known as interaction faults. Ltd Fault model .

In general. the faults are known as pairwise interaction faults.e. For t=2. Contents Foundations of Software Testing 2E Author: Aditya P. the faults are known as t--way interaction faults. i. are known as simple faults. Mathur 355 Copyright © 2013 Dorling Kindersley (India) Pvt.Faults triggered by some value of an input variable. for any arbitrary value of t. t=1. Ltd t-way interaction faults . regardless of the values of other input variables.

Ltd Pairwise interaction fault: Example . y) when X=x1 and Y=y1. z)-g(x. This is a pairwise interaction fault due to the interaction between factors X and Y. Mathur 356 Copyright © 2013 Dorling Kindersley (India) Pvt. Foundations of Software Testing 2E Contents Author: Aditya P.Correct output: f(x. y.

y=1. z=1 and x=-1. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 3-way interaction fault: Example .This fault is triggered by all inputs such that x+y≠x-y and z ≠ 0. Mathur 357 Copyright © 2013 Dorling Kindersley (India) Pvt. y=-1. the fault is revealed only by the following two of the eight possible input combinations: x=-1. However. z=1.

Ltd Fault vectors . a vector V of factor levels is (l1. V is considered as a t-fault vector if any t ≤ k elements in V are needed to trigger a fault in P. V is also known as a run.. each at qi. f2.. 1≤ i ≤ k levels.. Mathur 358 Copyright © 2013 Dorling Kindersley (India) Pvt.... where li. lk).Given a set of k factors f1. l2. Contents Foundations of Software Testing 2E Author: Aditya P. A run V is a fault vector for program P if the execution of P against a test case derived from V triggers a fault in P. fk. Note that a t-way fault vector for P triggers a t-way fault in P. 1 ≤ i ≤ k is a specific level for the corresponding factor.

1) and (-1. y. *) is a 2-way fault vector given that the values x1 and y1 trigger the twoway fault. 1) are three fault vectors that trigger the 3-way fault. (-1. (1. (x1. 1. and z each having two levels. Foundations of Software Testing 2E Contents Author: Aditya P. 0) are two runs. y1. Of these eight runs. There is a total of eight runs. Ltd Fault vectors: Example . For example.The input domain consists of three factors x. 1) and (-1. -1. -1. Mathur 359 Copyright © 2013 Dorling Kindersley (India) Pvt.1.

Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Goal reviewed The goal of the test generation techniques described in this chapter is to generate a sufficient number of runs such that tests generated from these runs reveal all t-way faults in the program under test. Mathur 360 .

Hence. t is set to 2 and hence the tests generated are expected to reveal pairwise interaction faults. t +k-1. Of course. one automatically generates some t+1. and k-way runs also. Ltd Goal reviewed .The number of such runs increases with the value of t. Mathur 361 Copyright © 2013 Dorling Kindersley (India) Pvt. In many situations. there is always a chance that runs generated with t=2 reveal some higher level interaction faults. Contents Foundations of Software Testing 2E Author: Aditya P. while generating t-way runs.. . t+2..

Mathur 362 .4. Latin squares Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 6.Copyright © 2013 Dorling Kindersley (India) Pvt.

A Latin square of order n is an n x n matrix such . 2. The term ``Latin square" arises from the fact that the early versions used letters from the Latin alphabet A.Latin Squares that no symbol appears more than once in a row and column. S={1. Ltd Let S be a finite set of n symbols. Contents Foundations of Software Testing 2E Author: Aditya P. B. B}. Mathur 363 Copyright © 2013 Dorling Kindersley (India) Pvt. Latin squares of order 2. C. in a square arrangement. 3}. Latin squares of order 3. etc. S={A.

here is a Latin square M of order 4 constructed by cyclically rotating the first row and placing successive rotations in subsequent rows. Ltd Larger Latin Squares Larger Latin squares of order n can be constructed by creating a row of n distinct symbols. For example.Copyright © 2013 Dorling Kindersley (India) Pvt. Additional rows can be created by permuting the first row. Mathur 364 . Contents Foundations of Software Testing 2E Author: Aditya P.

Contents Foundations of Software Testing 2E Author: Aditya P. 1≤ (i. A Latin square based on integers 0. j) ≤ 4. 1… n is said to be in standard form if the elements in the top row 0 and the leftmost column are arranged in order.A Latin square of order n>2 can also be constructed easily by doing modulo arithmetic. Ltd Modulo arithmetic and Latin Squares . the Latin square M of order 4 given below is constructed such that M(i. j)=i+j (mod 4). For example. Mathur 365 Copyright © 2013 Dorling Kindersley (India) Pvt.

5.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 6. Mutually orthogonal Latin squares Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 366 .

Mathur 367 Copyright © 2013 Dorling Kindersley (India) Pvt.e. j) and M2(i. j) . each of order n. we simply juxtapose the corresponding elements of M1 and M2.e. then M1 and M2 are said to be mutually orthogonal Latin squares of order n. respectively. We now create an n x n matrix M from M1 and M2 such that the L(i. Let M1(i. j)M2(i. i. Ltd Let M1 and M2 be two Latin squares. If each element of M is unique. i.Mutually Orthogonal Latin Squares (MOLS) denote. Contents Foundations of Software Testing 2E Author: Aditya P. it appears exactly once in M. the elements in the ith row and jth column of M1 and M2. j). j) is M1(i.

MOLS: Example Juxtaposing the corresponding elements gives us L. MOLS of order 3 follow. Contents Foundations of Software Testing 2E Author: Aditya P. Its elements are unique and hence M1 and M2 are MOLS. . Ltd There are no MOLS of order 2. Mathur 368 Copyright © 2013 Dorling Kindersley (India) Pvt.

MOLS do not exist for n=2 and n=6 but they do exist for all other values of n>2. Ltd MOLS: How many of a given order? . Numbers 2 and 6 are known as Eulerian numbers after the famous mathematician Leonhard Euler (1707-1783). MOLS(n) contains n-1 mutually orthogonal Latin squares. Contents Foundations of Software Testing 2E Author: Aditya P. The number of MOLS of order n is denoted by N(n).MOLS(n) is the set of MOLS of order n. Such a set of MOLS is a complete set. When n is prime or a power of prime. N(n)=n-1. or a power of prime. Mathur 369 Copyright © 2013 Dorling Kindersley (India) Pvt. When n is prime.

Copyright © 2013 Dorling Kindersley (India) Pvt. 4. Mathur 370 . 3. 2. Ltd MOLS: Construction [1] Example: We begin by constructing a Latin square of order 5 given the symbol set S={1. Contents Foundations of Software Testing 2E Author: Aditya P. 5}.

Contents Foundations of Software Testing 2E Author: Aditya P. Ltd MOLS: Construction [2] .Next. Mathur 371 Copyright © 2013 Dorling Kindersley (India) Pvt. we obtain M2 by rotating rows 2 through 5 of M1 by two positions to the left.

respectively. Contents Foundations of Software Testing 2E Author: Aditya P.MOLS: Construction [3] positions. It is easy to check that indeed the elements of MOLS(5) are mutually orthogonal by superimposing them pairwise. Mathur 372 Copyright © 2013 Dorling Kindersley (India) Pvt. we get MOLS(5)={M1. M3. M4}. Ltd M3 and M4 are obtained similarly but by rotating the first row of M1 by 3 and 4 . Thus. M2.

There is no general method available to construct the largest possible MOLS(n) for n that is not a prime or a power of prime. limitation . Contents Foundations of Software Testing 2E Author: Aditya P. Ltd MOLS: Construction. Mathur 373 Copyright © 2013 Dorling Kindersley (India) Pvt.The method illustrated in the previous example is guaranteed to work only when constructing MOLS(n) for n that is prime or a power of prime. For other values of n. The CRC Handbook of Combinatorial Designs gives a large table of MOLS. the maximum size of MOLS(n) is n-1.

Mathur 374 .Copyright © 2013 Dorling Kindersley (India) Pvt. Pairwise designs: Binary factors Contents Foundations of Software Testing 2E Author: Aditya P.6. Ltd 6.

Each combination selected generates at least one test input or test configuration for the program under test. factors are considered. Only 2-valued. This assumption will be relaxed later. Contents Foundations of Software Testing 2E Author: Aditya P. Each factor can be at one of two levels. Ltd Pairwise designs . or binary. Mathur 375 Copyright © 2013 Dorling Kindersley (India) Pvt.We will now look at a simple technique to generate a subset of factor combinations from the complete set.

X2}. Each variable can take only one of two distinct values. the total number of factor combinations is 23. Considering each input variable as a factor. one corresponding to each input .Pairwise designs: Example variable. Y. Mathur 376 Copyright © 2013 Dorling Kindersley (India) Pvt. Y2}. {Z1. Ltd Suppose that a program to be tested requires 3 inputs. Let X. Contents Foundations of Software Testing 2E Author: Aditya P. All possible combinations of these three factors follow. and Z denote the three input variables and {X1. {Y1. Z2} their respective sets of values.

Z1). Z1). Y2). (X1. Y1). . The following four combinations cover all pairs: The above design is also known as a pairwise design. Y2). (X2. and (Y2. Z2). (X2. Contents Foundations of Software Testing 2E Author: Aditya P. Z1). (X1. (Y1. (Y2. Z1). (X2. There are several sets of four combinations that cover all 12 pairs. Mathur 377 Copyright © 2013 Dorling Kindersley (India) Pvt. Z2). Z2). Y1).Pairwise designs: Reducing the combinations There are 12 such pairs: (X1. (X1. It is a balanced design because each value occurs exactly the same number of times. (Y1. Z2). Ltd Now suppose we want to generate tests such that each pair appears in at least one test. (X2.

Ltd Example: ChemFun applet . We refer to the inputs as factors. The applet has 5 inputs listed after the next slide with their possible values. Mathur 378 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.A Java applet ChemFun allows its user to create an in-memory database of chemical elements and search for an element. For simplicity we assume that each input has exactly two possible values.

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Example: ChemFun applet Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 379 .

Ltd Example: ChemFun applet: Factor identification Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 380 .

Ltd ChemFun applet: Input/Output Input: n=5 factors Output: A set of factor combinations such that all pairs of input values are covered. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 381 .Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 382 . k>0. Ltd Compute the smallest integer k such that n≤ |S2k-1| S2k-1: Set of all binary strings of length 2k-1. S2k-1= For k=3 we have S5= 10 and for k=2. S3= 3. Contents Foundations of Software Testing 2E Author: Aditya P. Hence the desired integer k=3.ChemFun applet: Step 1 Copyright © 2013 Dorling Kindersley (India) Pvt.

We have. Contents Foundations of Software Testing 2E Author: Aditya P.Select any subset of n strings from S2k-1. k=3 and we have the following strings in the set S5. Ltd ChemFun applet: Step 2 . We select first five of the 10 strings in S5. Mathur 383 Copyright © 2013 Dorling Kindersley (India) Pvt.

Contents Foundations of Software Testing 2E Author: Aditya P. Ltd ChemFun applet: Step 3 Append 0's to the end of each selected string. Mathur 384 .Copyright © 2013 Dorling Kindersley (India) Pvt. This will increase the size of each string from 2k-1 to 2k.

is a 0 or a 1. where the value of each variable is selected depending on whether the bit in column i. Xn). Ltd ChemFun applet: Step 4 . 1≤ i ≤ n. Mathur 385 Copyright © 2013 Dorling Kindersley (India) Pvt. X2.….Each combination is of the kind (X1. Contents Foundations of Software Testing 2E Author: Aditya P.

ChemFun applet: Step 4 (contd. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 386 .) Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd The following factor combinations by replacing the 0s and 1s in each column by the corresponding values of each factor.

Ltd ChemFun applet: tests Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 387 .

Recall that the total number of combinations is 32. Requiring only pairwise coverage reduces the tests to 6. Ltd ChemFun applet: All tests . Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 388 Copyright © 2013 Dorling Kindersley (India) Pvt.

Copyright © 2013 Dorling Kindersley (India) Pvt.7. Pairwise designs: Multi-valued factors Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 389 . Ltd 6.

Mathur 390 . Copyright © 2013 Dorling Kindersley (India) Pvt. •  The number of levels for each factor is more than two. Ltd Next we will learn how to use MOLS to construct test configurations when: Contents Foundations of Software Testing 2E Author: Aditya P.Pairwise designs: Multi-valued factors •  The number of factors is two or more. •  All factors have the same number of levels.

We refer to this software as AGTCS. One such facility is offered by The Applied Genomics Technology Center (AGTC) at the School of Medicine in Wayne State University. Mathur 391 . Contents Foundations of Software Testing 2E Author: Aditya P. Ltd DNA sequencing is a common activity amongst biologists and other researchers. The submission of the sample itself is done using a software application available from AGTC. Several genomics facilities are available that allow a DNA sample to be submitted for sequencing.Multi-valued factors: Sample problem Copyright © 2013 Dorling Kindersley (India) Pvt.

referred to as PI.Sample problem (contd. Ltd AGTCS is supposed to work on a variety of platforms that differ in their hardware .) and software configurations. Thus. must either have a profile already created with AGTCS or create a new one prior to submitting a sample. Contents Foundations of Software Testing 2E Author: Aditya P. the user of AGTCS. AGTCS supports only a limited set of browsers. In addition. the hardware platform and the operating system are two factors to be considered while developing a test plan for AGTCS. For simplicity we consider a total of four factors with their respective levels given next. Mathur 392 Copyright © 2013 Dorling Kindersley (India) Pvt.

As PCs and Macs run their dedicated operating systems. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd DNA sequencing: factors and levels .There are 64 combinations of the factors listed. the number of combinations reduces to 32. Mathur 393 Copyright © 2013 Dorling Kindersley (India) Pvt. We want to test under enough configurations so that all possible pairs of factor levels are covered.

12 asks you to take this approach and explore its advantages over the second approach used in this example. Contents Foundations of Software Testing 2E Author: Aditya P.We can now proceed to design test configurations in at least two ways. Ltd DNA sequencing: Approach to test design . One way is to treat the testing on PC and Mac as two distinct problems and design the test configurations independently. The approach used in this example is to arrive at a common set of test configurations that obey the constraint related to the operating systems. Exercise 6. Mathur 394 Copyright © 2013 Dorling Kindersley (India) Pvt.

|F1’|=2. OS. where F1’. respectively.Input: n=4 factors. and PI. Mathur 395 Copyright © 2013 Dorling Kindersley (India) Pvt. |F2’|=4. browser. F3’. and F4’ denote. F2’. hardware. |F3’|=4. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd DNA sequencing: Test design algorithm . |F4’|=2. Output: A set of factor combinations such that all pairwise combinations are covered.

Doing so gives us F1=F2'. Ltd Reliable the factors as F1. Let b=|F1|=4 and k=|F2|=4 Contents Foundations of Software Testing 2E Author: Aditya P. F2=F3'. F3. F4 such that |F1|≥|F2| ≥ |F3| ≥ |F4|. Note that a different assignment is also possible because |F1|=|F4|and |F2|=|F3|. F2. Mathur 396 .Test design algorithm: Step 1 Copyright © 2013 Dorling Kindersley (India) Pvt. b=k=4. F4=F4'. F3=F1'.

Copyright © 2013 Dorling Kindersley (India) Pvt. Each block contains k rows. … Fn. Label the columns as F1. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 397 . Ltd Test design algorithm: Step 2 Prepare a table containing 4 columns and b x k=16 rows divided into 4 blocks. F2.

2.. and so on.. Fill Block 1 of column F2 with the sequence 1. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Test design algorithm: Step 3 (contd.. k in rows 1 through k (k=4).) Fill column F1 with 1's in Block 1.Copyright © 2013 Dorling Kindersley (India) Pvt. 2's in Block 2. Mathur 398 .

We choose the following set of MOLS of order 4. we can use the procedure described earlier. Mathur 399 . Contents Foundations of Software Testing 2E Author: Aditya P. As 4 is a power of prime.Test design algorithm: Step 4 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Find MOLS of order 4.

A boxed entry in each row indicates a pair that does not satisfy the operating system constraint. An entry marked with an asterisk (*) indicates an invalid level. Ltd From M1 Fill the remaining two columns of the table constructed earlier using columns of M1 for F3 and M2 for F4. Mathur 400 .Test design algorithm: Step 5 From M2 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.

. we can obtain 16 distinct test configurations for AGTCS. Ltd Test design algorithm: Step 6 [1] . Contents Foundations of Software Testing 2E Author: Aditya P. Solution: One simple way to get rid of the infeasible values is to replace them by an arbitrarily selected feasible value for the corresponding factor. we need to resolve two problems before we get to the design of test configurations. These infeasible values are marked with an asterisk. However. Problem 1: Factors F3 and F4 can only assume values 1 and 2 whereas the table above contains other infeasible values for these two factors.Using the 16 entries in the table above. Mathur 401 Copyright © 2013 Dorling Kindersley (India) Pvt.

Foundations of Software Testing 2E Author: Aditya P. Four such configurations are highlighted in the design by enclosing the corresponding numbers in rectangles. Here is an example: F1: Operating system=1(Win 2000) F3: Hardware=2 (Mac) is infeasible. Ltd Test design algorithm: Step 6 [2] .Problem 2: Some configurations do not satisfy the operating system constraint. Mathur Contents 402 Copyright © 2013 Dorling Kindersley (India) Pvt. Here we are assume that one is not using Virtual PC on the Mac.

Removing Row~3 will leave the following five pairs uncovered: (F1=3. (F2=3. F4=2). Mathur 403 Copyright © 2013 Dorling Kindersley (India) Pvt. Consider block 3. and (F3=1. F3=1). Contents Foundations of Software Testing 2E Author: Aditya P.Delete rows with conflicts?: Obviously we cannot delete these rows as that would leave some pairs uncovered. F4=2). F4=2). (F1=3. Ltd Test design algorithm: Step 6 [3] . (F2=3. F2=3).

Contents Foundations of Software Testing 2E Author: Aditya P. Step 1: Modify the four highlighted rows so they do not violate the constraint. Step 2: Add new configurations that cover the pairs that are left uncovered when we replace the highlighted rows.Test design algorithm: Step 6 [4] Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Proposed solution: We follow a two step procedure to remove the highlighted configurations and retain complete pairwise coverage. Mathur 404 .

Ltd F1: OS Contents Foundations of Software Testing 2E Author: Aditya P.Test design algorithm: Step 6 [5] F2: Browser F4: PI F3: Hardware Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 405 .

Mathur 406 . This is in contrast to 32 configurations obtained using a brute force method.Test design algorithm: Design configurations Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd We can easily construct 20 test configurations from the design obtained. Can we remove some rows from the design without affecting pairwise coverage? Contents Foundations of Software Testing 2E Author: Aditya P.

the number of test configurations is often larger than what can be achieved using other methods. Ltd A sufficient number of MOLS might not exist for the problem at hand.Shortcomings of using MOLS Copyright © 2013 Dorling Kindersley (India) Pvt. While the MOLS approach assists with the generation of a balanced design in that all interaction pairs are covered an equal number of times. Mathur 407 . Contents Foundations of Software Testing 2E Author: Aditya P.

Mathur 408 . Ltd 6. Orthogonal Arrays Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.8.

is an N x k matrix in which the entries are from a finite set S of s symbols such that any N x t sub array contains each t-tuple exactly the same number of times. Ltd Examine this matrix and extract as many properties as you can: . k.Orthogonal arrays An orthogonal array. t). s. Such an orthogonal array is denoted by OA(N. such as the one above. Foundations of Software Testing 2E Contents Author: Aditya P. Mathur 409 Copyright © 2013 Dorling Kindersley (India) Pvt.

F2. and F3 to indicate the three factors. 3.The following orthogonal array has 4 runs and has a strength of 2. 2. Mathur 410 Copyright © 2013 Dorling Kindersley (India) Pvt. Note that the value of parameter k is 3 and hence we have labeled the columns as F1. It uses symbols from the set {1. Contents Foundations of Software Testing 2E Author: Aditya P. 2}. Ltd Orthogonal arrays: Example . This array is denoted as OA(4. 2).

and (2. 2). (2. N is referred to .Orthogonal arrays: Index as the number of runs and t as the strength of the orthogonal array. Contents Foundations of Software Testing 2E Author: Aditya P. There is a total of st=22=4 pairs given as (1. (1. Mathur 411 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd The index of an orthogonal array is denoted by λ and is equal to N/st. 1). 1). 2). λ =4/22=1 implying that each pair (t=2) appears exactly once (λ =1) in any 4 x 2 sub array. It is easy to verify that each of the four pairs appears exactly once in each 4 x 2 sub array.

Ltd Orthogonal arrays: Another example . Mathur 412 Copyright © 2013 Dorling Kindersley (India) Pvt. Each of the four factors can be at any one of 3 levels. 4.What kind of an OA is this? It has 9 runs and a strength of 2. This array is denoted as OA(9. Contents Foundations of Software Testing 2E Author: Aditya P. 2) and has an index of 1. 3.

Contents Foundations of Software Testing 2E Author: Aditya P. s are determined from the context.e. Mathur 413 .Orthogonal arrays: Alternate notations Copyright © 2013 Dorling Kindersley (India) Pvt. t. by examining the array itself. Ltd Orthogonal array of N runs where k factors take on any value from a set of s symbols. i. Arrays shown earlier are LN denotes an orthogonal array of 9 runs. k.

Mixed-level Orthogonal Arrays Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 6. Mathur 414 .9.

each taking on a different set of values. Mixed orthogonal arrays are useful in designing test configurations for such applications. one encounters more than one factor. Mathur 415 . Ltd So far we have seen fixed level orthogonal arrays. Contents Foundations of Software Testing 2E Author: Aditya P. In many practical applications. This is because the design of such arrays assumes that all factors assume values from the same set of s values.Mixed level Orthogonal arrays Copyright © 2013 Dorling Kindersley (India) Pvt.

and so on. Mathur 416 .Copyright © 2013 Dorling Kindersley (India) Pvt. Runs=N. Ltd Mixed level Orthogonal arrays: Notation Strength=t. k2 at s2 levels. Total factors: Contents Foundations of Software Testing 2E Author: Aditya P. k1 factors at s1 levels.

Contents Foundations of Software Testing 2E Author: Aditya P.Mixed level Orthogonal arrays: Index and balance Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd The formula used for computing the index λ of an orthogonal array does not apply to the mixed level orthogonal array as the count of values for each factor is a variable. which is λ. The balance property of orthogonal arrays remains intact for mixed level orthogonal arrays in that any N x t sub array contains each t-tuple corresponding to the t columns. exactly the same number of times. Mathur 417 .

Ltd Mixed level Orthogonal arrays: Example .This array can be used to design test configurations for an application that contains 4 factors each at 2 levels and 1 factor at 4 levels. each pair occurs exactly once. In the two leftmost columns. each possible pair occurs exactly the same number of times. each pair occurs exactly twice. Contents Foundations of Software Testing 2E Author: Aditya P. Can you identify some properties? Balance: In any sub array of size 8 x 2. In columns 1 and 3. Mathur 418 Copyright © 2013 Dorling Kindersley (India) Pvt. In columns 1 and 5. each pair also occurs exactly twice.

Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Mixed level Orthogonal arrays: Example This array can be used to generate test configurations when there are six binary factors. labeled F7 through F9. labeled F1 through F6 and three factors each with four possible levels. Mathur 419 .

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Mixed level Orthogonal arrays: Test generation: Pizza delivery We have 3 binary factors and one factor at 3 levels. Mathur 420 . Hence we can use the following array to generate test configurations: Contents Foundations of Software Testing 2E Author: Aditya P.

Check that all possible pairs of factor combinations are covered in the design above. Ltd Test generation: Pizza delivery: Array . Mathur 421 Copyright © 2013 Dorling Kindersley (India) Pvt. What kind of errors will likely be revealed when testing using these 12 configurations? Contents Foundations of Software Testing 2E Author: Aditya P.

Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 422 . Ltd Test generation: Pizza delivery: test configurations Contents Foundations of Software Testing 2E Author: Aditya P.

9.Copyright © 2013 Dorling Kindersley (India) Pvt. Covering and mixed-level covering arrays Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 423 . Ltd 6.

and when repeatability is not the focus. For deterministic applications. we can relax the balance requirement and use covering arrays. if a software application has been tested once for a given pair of factor levels. or mixed level covering arrays for combinatorial designs. For example.The “Balance” requirement Observation [Dalal and Mallows. Foundations of Software Testing 2E Contents Author: Aditya P. Mathur 424 . it is not always so in software testing. Ltd essential in statistical experiments. there is generally no need for testing it again for the same pair. 1998]: The balance requirement is often Copyright © 2013 Dorling Kindersley (India) Pvt. unless the application is known to behave non-deterministically.

we use λ=1. the number of levels for each factor. k. t) is an N x k matrix in which entries are from a finite set S of s symbols such that each N x t sub-array contains each possible t-tuple at least λ times. Mathur 425 Copyright © 2013 Dorling Kindersley (India) Pvt. N denotes the number of runs. Ltd Covering array . t the strength. k the number factors. and λ the index While generating test cases or test configurations for a software application. Contents Foundations of Software Testing 2E Author: Aditya P. s. s.A covering array CA(N.

t) covers each possible t-tuple at least λ times in any N x t sub array. Contents Foundations of Software Testing 2E Author: Aditya P. k. s. Mathur 426 Copyright © 2013 Dorling Kindersley (India) Pvt. Thus. Ltd Covering array and orthogonal array . k. a covering array CA(N. We are interested in minimal covering arrays. Covering arrays are also referred to as unbalanced designs. This difference leads to combinatorial designs that are often smaller in size than orthogonal arrays. s. covering arrays do not meet the balance requirement that is met by orthogonal arrays.While an orthogonal array OA(N. t) covers each possible t-tuple λ times in any N x t sub array.

2. 2). a covering design with the same parameters requires only 6 runs. Mathur 427 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. 5. requires 8 runs and is denoted by . Ltd A balanced design of strength 2 for 5 binary factors.Covering array: Example OA(8. However.

Mathur 428 Copyright © 2013 Dorling Kindersley (India) Pvt..A mixed-level covering array is denoted as p and refers to an N x Q matrix of entries such that. Ltd Mixed level covering arrays . Contents Foundations of Software Testing 2E Author: Aditya P. s2. Q= ∑k i and each N x t sub- i=1 array contains at least one occurrence of each t-tuple corresponding to the t columns.… denote the number of levels of each the corresponding factor. € Mixed-level covering arrays are generally smaller than mixed-level orthogonal arrays and more appropriate for use in software testing. s1.

Is the above array balanced? Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 429 .Comparing this with Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Mixed level covering array: Example we notice a reduction of 6 configurations.

Ltd 6. Mathur 430 .Copyright © 2013 Dorling Kindersley (India) Pvt.10. Arrays of strength >2 Contents Foundations of Software Testing 2E Author: Aditya P.

Arrays of strength >2 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Designs with strengths higher than 2 are sometimes needed to achieve higher confidence in the correctness of software. Contents Foundations of Software Testing 2E Author: Aditya P. Consider the following factors in a pacemaker. Mathur 431 .

we would like to test it to . Thus. 5. 3. Ltd Due to the high reliability requirement of the pacemaker. we need a suitable combinatorial object with strength 3. Thus.Pacemaker example ensure that there are no pairwise or 3-way interaction errors. Mathur Contents 432 Copyright © 2013 Dorling Kindersley (India) Pvt. We could use an orthogonal array OA(54. 3) that has 54 runs for 5 factors each at 3 levels and is of strength 3. a total of 54 tests will be required to test for all 3-way interactions of the 5 pacemaker parameters Could a design of strength 2 cover some triples and higher order tuples? Foundations of Software Testing 2E Author: Aditya P.

Mathur 433 .Generating mixed level covering arrays Copyright © 2013 Dorling Kindersley (India) Pvt. Inputs: (a) n ≥2: Number of parameters (factors). The procedure is known as In-parameter Order (IPO) procedure. (b) Number of values (levels) for each parameter. Output: MCA Contents Foundations of Software Testing 2E Author: Aditya P. Ltd We will now study a procedure due to Lei and Tai for the generation of mixed level covering arrays.

11.Copyright © 2013 Dorling Kindersley (India) Pvt. Generating covering arrays Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 434 . Ltd 6.

Ltd Consists of three steps: Step 1: Main procedure. Contents Foundations of Software Testing 2E Author: Aditya P. Step 2: Horizontal growth. Mathur 435 . Step 3: Vertical growth.IPO procedure Copyright © 2013 Dorling Kindersley (India) Pvt.

B. a3}. Contents Foundations of Software Testing 2E Author: Aditya P. a2. B from the set {b1. c3}.IPO procedure: Example Copyright © 2013 Dorling Kindersley (India) Pvt. b2}. and C. Ltd Consider a program with three factors A. A assumes values from the set {a1. and C from the set {c1. Mathur 436 . c2.. We begin by applying the Main procedure which is the first step in the generation of an MCA using the IPO procedure. We want to generate a mixed level covering array for these three factors.

IPO procedure: main procedure Copyright © 2013 Dorling Kindersley (India) Pvt. We obtain the following set. The entire IPO procedure would terminate at this point if the number of parameters n=2. t2. Contents Foundations of Software Testing 2E Author: Aditya P.…t6. In our case n=3 hence we continue with horizontal growth. Let us denote the elements of as t1. Mathur 437 . Ltd Main: Step 1: Construct all runs that consist of pairs of values of the first two parameters.

Mathur 438 . This leads us to the following set of fifteen pairs. At this point T’ is empty as we have not extended any run in T. Ltd HG: Step 1: Compute the set of all pairs AP between parameters A and C. Contents Foundations of Software Testing 2E Author: Aditya P. and parameters B and C.IPO procedure: Horizontal growth Copyright © 2013 Dorling Kindersley (India) Pvt. Let T’ denote the set of runs obtained by extending the runs in T. HG: Step 2: AP is the set of pairs yet to be covered.

c2). (a1. c1). (a3. c3. c3). b1. (b2. b1. c1). Ltd HG: Steps 3. b2. (a2. This gives us: t1’=(a1. c3)} Update pairs remaining to be covered AP={(a1. b1. c3) Update T’ which now becomes {a1. c1). c1). (a3. (a2. (b1. t2. c2). t2’=(a1. c3)} Update T’ which becomes {(a1. b1. c1). (a1. c2). b2. t3 by appending c1. and t3’=(a2.Horizontal growth: Extend Copyright © 2013 Dorling Kindersley (India) Pvt. 4: Expand t1. c2). b1. c2). (a2. c3)} Contents Foundations of Software Testing 2E Author: Aditya P. c3). (a2. b1. c1). c2. Mathur 439 . (b2. b2. (a3. c2).

If we extend t4=(a2. If we extend it by c2 then we cover one pair from AP. c1) and (b2. Step 5: We have not extended t4.Horizontal growth: Optimal extension Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd HG. HG: Step 6: Expand t4. Mathur 440 . Thus. (a2. We find the best way to extend these in the next step. Contents Foundations of Software Testing 2E Author: Aditya P. If we extend it by c3 then we cover one pairs in AP. t5. t6 by suitably selected values of C. namely. t6 as C does not have enough elements. c1). t5. we choose to extend t4 by c1. b2) by c1 then we cover two of the uncovered pairs from AP.

b1. (b1. c2). b2. b1. (b2. c2). b2. c3). c3). (a3. c3) and t6’=(a3. Ltd T’={(a1. (b2. c1). c1)} AP= {(a1. c2). c2). b1. b2. (a3. c3). b2. (a1. (a1. b1. c1). b2. c1) T’={(a1. c3). (b1. (a3. Mathur 441 . c2). (a2. c2). c1). c1). (a3. This leads to: t5’=(a3. (a2. c1)} AP= {(a1. b1. c3)} HG: Step 6: Similarly we extend t5 and t6 by the best possible values of parameter C. c2). c3)} Contents Foundations of Software Testing 2E Author: Aditya P. (a3. (a2. (a2. b1. c3).Horizontal growth: Update and extend remaining Copyright © 2013 Dorling Kindersley (India) Pvt. (a3. c2). b2. (a2. c3). (a2.

However. c3). we have generated six complete runs namely: T’={(a1. Mathur 442 . b1. we have five pairs remaining to be covered. b2. (b2. c1). (a2. These are: AP= {(a1. b1. c1)} We now move to the vertical growth step of the main IPO procedure to cover the remaining pairs. b2. (a1. c2). c3). (a3. Ltd We have completed the horizontal growth step. c1). c2). c2). b2. (b1. b1.Horizontal growth: Done Copyright © 2013 Dorling Kindersley (India) Pvt. (a3. (a2. c3). c2). Contents Foundations of Software Testing 2E Author: Aditya P. c3)} Also. (a2. (a3.

c2) Next . This is covered by the run (a2. c2). consider p=(a3. This is covered by the run (a3. *. Next . c3).Vertical growth Copyright © 2013 Dorling Kindersley (India) Pvt. we will add a new run to T’ such that p is covered. Ltd For each missing pair p from AP. Let us begin with the pair p= (a1. c2) Contents Foundations of Software Testing 2E Author: Aditya P. c2). *. Note that the value of parameter Y does not matter and hence is indicated as a * which denotes a don’t care value. The run t= (a1. consider p=(a2. c3) covers pair p. *. Mathur 443 .

b1. Thus. Mathur 444 Copyright © 2013 Dorling Kindersley (India) Pvt. Finally. c1). c2). b1. (a3. b1. b2. We already have (a1. c2).) to get the run (a1. b1. c3). c3). c1). b2. We already have (a3.Vertical growth (contd. *. c3) and hence we can modify it . c2) and hence we can modify it to get the run (a3. (a3. c1). b1. p is covered without any new run added. (a1. (a2. Ltd Next . b2. (a1. consider p=(b1. c2). b2. (a2. c2). Thus. c3). c2)} Contents Foundations of Software Testing 2E Author: Aditya P. c3). b1. consider p=(b2. b2. We replace the don’t care entries by an arbitrary value of the corresponding factor and get: T={(a1. (a3. *. c3). (a2. p is covered without any new run added.

Mathur 445 . 21 32. 2) Run F1(X) F2(Y) F3(Z) 1 1 1 1 2 1 2 2 3 1 2 3 4 2 1 2 5 2 1 3 6 2 2 1 7 3 1 2 8 3 1 3 9 3 2 1 Copyright © 2013 Dorling Kindersley (India) Pvt.MCA(9. Ltd Final covering array Contents Foundations of Software Testing 2E Author: Aditya P.

Contents Foundations of Software Testing 2E Author: Aditya P. Lei and Tai found that the IPO algorithm performs almost as well as AETG in the size of the generated arrays. Mathur 446 Copyright © 2013 Dorling Kindersley (India) Pvt. Lei and Tai offer several other algorithms for horizontal and vertical growth that are faster than the algorithm mentioned here. Ltd Practicalities . A detailed analysis of the algorithm has been given by Lei and Tai.That completes our presentation of an algorithm to generate covering arrays.

Mathur 447 . Publicly available tool: ACTS from Jeff Lie’s group a UT Arlington. parameter A might not assume a value a2 when parameter B assumes value b3. Contents Foundations of Software Testing 2E Author: Aditya P. It allows users to specify constraints across parameters. AETG is covered by US patent 5.043.Tools Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd AETG from Telcordia is a commercial tool to generate covering arrays.542. For example.

Summary Combinatorial design techniques assist with the design of test configurations and Copyright © 2013 Dorling Kindersley (India) Pvt. MOLS. This continues to be a research topic of considerable interest. covering arrays. For software testing. We introduced one algorithm for generating covering arrays. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd test cases. By requiring only pair-wise coverage and relaxing the “balance requirement. and mixed-level covering arrays are used as combinatorial objects to generate test configurations/test cases.” combinatorial designs offer a significant reduction in the number of test configurations/test cases. most useful amongst these are mixed level covering arrays. Handbooks offer a number covering and mixed level covering arrays. Mathur 448 . Orthogonal arrays.

Ltd Chapter 7 .Test Adequacy Measurement and Enhancement: Control and Data flow Updated: July 16. Mathur 449 Copyright © 2013 Dorling Kindersley (India) Pvt. 2013 Foundations of Software Testing 2E Contents Author: Aditya P.

Learning Objectives What is test adequacy? What is test enhancement? When to measure test Copyright © 2013 Dorling Kindersley (India) Pvt. statement. multiple condition. Ltd §  adequacy and how to use it to enhance tests? §  Control flow based test adequacy. LCSAJ. Mathur 450 . decision. and MC/DC coverage §  Data flow coverage §  Strengths and limitations of code coverage based measurement of test adequacy §  The “subsumes” relation amongst coverage criteria §  Tools for the measurement of code coverage Contents Foundations of Software Testing 2E Author: Aditya P. condition.

1 Test adequacy: basics Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 7.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 451 .

§  Suppose now that a set T containing k tests has been constructed to test P to determine whether or not it meets all the requirements in R . Let R contain n requirements labeled R1. R). Ltd §  .What is adequacy? Consider a program P written to meet a set R of functional requirements. §  We now ask: Is T good enough? This question can be stated differently as: Has P been tested thoroughly?. R2. or as: Is T adequate? Contents Foundations of Software Testing 2E Author: Aditya P. We notate such a P and R as ( P.…. Rn . Also. P has been executed against each test in T and has produced correct behavior. Mathur 452 Copyright © 2013 Dorling Kindersley (India) Pvt.

Measurement of adequacy In the context of software testing. The determination of whether or not a test set T for program P satisfies criterion C depends on the criterion itself and is explained later." ``good enough. §  This measurement is done against a given criterion C ." and ``adequate. Contents Foundations of Software Testing 2E Author: Aditya P. A test set is considered adequate with respect to criterion C when it satisfies C. have the same meaning." used in the questions above. §  Adequacy is measured for a given test set designed to test P to determine whether or not P meets its requirements. Ltd §  . the terms ``thorough. Mathur 453 Copyright © 2013 Dorling Kindersley (India) Pvt.

R2. Mathur 454 .2 Find and print to the standard output device the product of x and y if x≥ y. R2. say x and y . Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Program sumProduct must meet the following requirements: Contents Foundations of Software Testing 2E Author: Aditya P.1 Find and print to the standard output device the sum of x and y if x<y .Example R1 Input two integers. from the standard input device.

Ltd Suppose now that the test adequacy criterion C is specified as: . T={t: <x=2.) C : A test T for program ( P. y=3> is inadequate with respect to C for program sumProduct. Contents Foundations of Software Testing 2E Author: Aditya P. The lone test case t in T tests R1 and R2. Mathur 455 Copyright © 2013 Dorling Kindersley (India) Pvt.1.Example (contd. Obviously. R ) is considered adequate if for each requirement r in R there is at least one test case in T that tests the correctness of P with respect to r .2. but not R2.

Contents Foundations of Software Testing 2E Author: Aditya P. A criterion C is a white-box test adequacy criterion if the corresponding coverage domain Ce depends solely on program P under test.For each adequacy criterion C . A criterion C is a black-box test adequacy criterion if the corresponding coverage domain Ce depends solely on requirements R for the program P under test. Ltd Black-box and white-box criteria . we derive a finite set known as the coverage domain and denoted as Ce . Mathur 456 Copyright © 2013 Dorling Kindersley (India) Pvt.

This fraction is also known as the coverage of T with respect to C .Coverage We want to measure the adequacy of T. Ltd that T covers Ce if for each element e' in Ce there is at least one test case in T that tests e'. and R. Contents Foundations of Software Testing 2E Author: Aditya P. we say Copyright © 2013 Dorling Kindersley (India) Pvt. Given that Ce has n≥ 0 elements. T is considered inadequate with respect to C if it covers k elements of Ce where k<n . T is considered adequate with respect to C if it covers all elements in the coverage domain. P . Mathur 457 . The fraction k/n is a measure of the extent to which T is adequate with respect to C . The notion of “tests” is explained later through examples.

Mathur 458 Copyright © 2013 Dorling Kindersley (India) Pvt.1. Contents Foundations of Software Testing 2E Author: Aditya P. P.Let us again consider the following criterion: “A test T for program ( P. R ) is considered adequate if for each requirement r in R there is at least one test case in T that tests the correctness of P with respect to r. The coverage of T with respect to C. and R is 0. T covers R1 and R2. Ltd Example .” In this case the finite set of elements Ce={R1.1 but not R2.2 . Hence T is not adequate with respect to C . R2.66.2}. R2.

R ) is considered adequate if each path in P is traversed at least once.” Assume that P has exactly two paths. For the given adequacy criterion C we obtain the coverage domain Ce to be the set { p1. Contents Foundations of Software Testing 2E Author: Aditya P. We refer to these as p1 and p2.Consider the following criterion: “A test T for program ( P. respectively. one corresponding to condition x<y and the other to x≥ y. p2}. Mathur 459 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Another Example .

) . we execute P against each test case in T . Mathur 460 Copyright © 2013 Dorling Kindersley (India) Pvt.To measure the adequacy of T of sumProduct against C . Ltd Another Example (contd. As T contains only one test for which x<y . Thus. only the path p1 is executed. and R is 0. Contents Foundations of Software Testing 2E Author: Aditya P. the coverage of T with respect to C.5 and hence T is not adequate with respect to C. P . We can also say that p1 is tested and p2 is not tested.

However. Errors in the program and incomplete or incorrect requirements might cause the program. when the coverage domain must contain elements from the code.Code-based coverage domain Copyright © 2013 Dorling Kindersley (India) Pvt. and hence the coverage domain. these elements must be derived by analyzing the code and not only by an examination of its requirements. Mathur 461 . This assumption is based on a knowledge of the requirements. Contents Foundations of Software Testing 2E Author: Aditya P. to be different from the expected. Ltd In the previous example we assumed that P contains exactly two paths.

Mathur 462 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd sumProduct1 . y=3> }is adequate w. This path traverses all the statements. C but does not reveal the error. T={t: <x=2. Using the path-based coverage criterion C.r. we get coverage domain Ce={ p1}. There is only one path denoted as p1.Example This program is obviously incorrect as per the requirements of sumProduct.t. Contents Foundations of Software Testing 2E Author: Aditya P.

Mathur 463 . p2}.r. y=3>} is inadequate w.Example (contd.) Copyright © 2013 Dorling Kindersley (India) Pvt. It has two paths denoted by p1 and p2.t. the path-based coverage criterion C. T={t: <x=2. Ltd sumProduct2 This program is correct as per the requirements of sumProduct. Contents Foundations of Software Testing 2E Author: Aditya P. Ce={ p1.

Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 464 . Ltd Lesson An adequate test set might not reveal even the most obvious error in a program. This does not diminish in any way the need for the measurement of test adequacy as increasing coverage might reveal an error!.

1. Ltd 7.3 Test enhancement Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 465 .Copyright © 2013 Dorling Kindersley (India) Pvt.

an inadequate test set is a cause for worry. Enhancement in turn is also likely to test the program in ways it has not been tested before such as testing untested portion.Test Enhancement free program. or testing the features in a sequence different from the one used previously. Testing the program differently than before raises the possibility of discovering any uncovered errors. Mathur 466 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Inadequacy with respect to any criterion often implies test deficiency. Ltd While a test set adequate with respect to some criterion does not guarantee an error- . Identification of this deficiency helps in the enhancement of the inadequate test set.

One test that does so is {<x=3>. Thus. Ltd For sumProduct2. t2: <x=3. y=1>} Executing sum-product-2 against the two tests in T’ causes paths p1 and p2 are traversed. Contents Foundations of Software Testing 2E Author: Aditya P.Test Enhancement: Example Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 467 . y=1>}. to make T adequate with respect to the path coverage criterion we need to add a test that covers p2. Adding this test to T and denoting the expanded test set by T' we get: T'={t1: <x=3. y=4>. T' is adequate with respect to the path coverage criterion.

Mathur 468 . Ltd Test Enhancement: Procedure Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

For y<0 the program skips the computation and outputs a suitable error message.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 469 . Ltd Test Enhancement: Example Consider a program intended to compute xy given integers x and y. Contents Foundations of Software Testing 2E Author: Aditya P.

Test Enhancement: Example (contd. y=0}. y=1>. Again. Ltd program for at least one zero and one non-zero value of each of the two inputs x and y. one can derive an adequate test set for the program by an examination of Ce. t2: <x=1. y=0>}. Mathur 470 . x≠0. Contents Foundations of Software Testing 2E Author: Aditya P. y≠ 0. The coverage domain for C can be determined using C alone and without any inspection of the program For C we get Ce={x=0. One such test set is T={t1: <x=0.) Suppose that test T is considered adequate if it tests the exponentiation Copyright © 2013 Dorling Kindersley (India) Pvt.

An examination of the exponentiation program reveals that it has an indeterminate number of paths due to the while loop. Ltd Test Enhancement: Example: Path coverage . Contents Foundations of Software Testing 2E Author: Aditya P. The number of paths depends on the value of y and hence that of count.Criterion C of the previous example is a black-box coverage criterion as it does not require an examination of the program under test for the measurement of adequacy Let us now consider the path coverage criterion defined in in an earlier example. Mathur 471 Copyright © 2013 Dorling Kindersley (India) Pvt.

In case the program contains a loop. The usual approach in such cases is to simplify C and reformulate it as follows: A test T is considered adequate if it tests all paths.) . Mathur 472 Copyright © 2013 Dorling Kindersley (India) Pvt. then it is adequate to traverse the loop body zero times and once. This simple analysis of paths in exponentiation reveals that for the path coverage criterion we cannot determine the coverage domain. Ltd Example: Path coverage (contd. Contents Foundations of Software Testing 2E Author: Aditya P.Given that y is any non-negative integer. the number of paths can be arbitrarily large.

Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Example: Path coverage (contd. p2.) . The elements of Ce’ are enumerated below with respect to flow graph for the exponentiation program. Mathur 473 Copyright © 2013 Dorling Kindersley (India) Pvt. p3}.The modified path coverage criterion leads to C‘e={p1.

Thus. Mathur 474 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.We measure the adequacy of T with respect to C'. Ltd Example: Path coverage (contd. As T does not contain any test with y<0. the coverage of T with respect to C' is 2/3=0.66. p3 remains uncovered.) .

y=-1>. The loop in the enhancement terminates as we have covered all feasible elements of Ce’. Ltd Any test case with y<0 will cause p3 to be traversed. <x=5. The enhanced test set is: T={<x=0. Let . y=0>. y=1>.Example: Path coverage (contd. Mathur 475 Copyright © 2013 Dorling Kindersley (India) Pvt. Test t covers path p3 and P behaves correctly.) us use t:<x=5. We add t to T. <x=1. y=-1>} Contents Foundations of Software Testing 2E Author: Aditya P.

Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 476 . Ltd 7.4 Infeasibility and test adequacy Contents Foundations of Software Testing 2E Author: Aditya P.1.

There does not exist an algorithm that would analyze a given program and determine if a given element in the coverage domain is infeasible or not. Mathur 477 . Ltd An element of the coverage domain is infeasible if it cannot be covered by any test in the input domain of the program under test.Infeasibility Copyright © 2013 Dorling Kindersley (India) Pvt. it is usually the tester who determines whether or not an element of the coverage domain is infeasible. Contents Foundations of Software Testing 2E Author: Aditya P. Thus.

Mathur 478 . Contents Foundations of Software Testing 2E Author: Aditya P. an attempt to enhance a test set by executing a test aimed at covering element e of program P. might fail. Thus.Demonstrating feasibility Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Feasibility can be demonstrated by executing the program under test against a test case and showing that indeed the element under consideration is covered. For complex programs the problem of determining infeasibility could be difficult. Infeasibility cannot be demonstrated by program execution against a finite number of test cases. In some cases simple arguments can be constructed to show that a given element is infeasible.

Infeasible path: Example

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

This program inputs two integers x and y, and
computes z. Ce={p1, p2, p3}.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

479

p1 is infeasible and cannot be traversed by any test case.
This is because when control reaches node 5, condition
y≥0 is false and hence control can never reach node 6.

Thus, any test adequate with respect to the path
coverage criterion for the exponentiation program will
only cover p2 and p3
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

480

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Example: Flow graph and paths

Adequacy and infeasibility

considered adequate when all feasible elements in the domain have been covered.

While programmers might not be concerned with infeasible elements, testers
attempting to obtain code coverage are. Prior to test enhancement, a tester usually does
not know which elements of a coverage domain are infeasible. Unfortunately, it is only
during an attempt to construct a test case to cover an element that one might realize
the infeasibility of an element.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

481

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

In the presence of one or more infeasible elements in the coverage domain, a test is

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

7.1.5 Error detection and test enhancement

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

482

The purpose of test enhancement is to determine test cases that test the untested
parts of a program or exercise the program using uncovered portions of the input
domain. Even the most carefully designed tests based exclusively on requirements
can be enhanced.
The more complex the set of requirements, the more likely it is that a test set designed
using requirements is inadequate with respect to even the simplest of various test
adequacy criteria.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

483

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Test enhancement

Example

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

A program to meet the following requirements is to be developed.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

484

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Example (contd.)

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

485

Example (contd.)

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Consider the following program written to meet the requirements stated earlier.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

486

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Example (contd.)

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

487

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Example (contd.)

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

488

Example (contd.)

whether or not our program meets its requirements.
T={<request=1, x=2, y=3>, <request=2, x=4>, <request=3>}

For the first two of the three requests the program correctly outputs 8 and 24,
respectively. The program exits when executed against the last request. This program
behavior is correct and hence one might conclude that the program is correct. It will
not be difficult for you to believe that this conclusion is incorrect.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

489

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Suppose now that the following set containing three tests has been developed to test

Let us now evaluate T against the path coverage criterion.
In class exercise: Go back to the example
program and extract the paths not covered by T.

The coverage domain consists of all paths that traverse each of the three loops zero
and once in the same or different executions of the program. This is left as an exercise
and we continue with one sample, and “tricky,” uncovered path.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

490

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Example (contd.)

Example (contd.)

line 10, then the first if at line 12, followed by the statements that compute the
factorial starting at line 20, and then the code to compute the exponential starting at
line 13.

p is traversed when the program is launched and the first input request is to compute
the factorial of a number, followed by a request to compute the exponential. It is easy
to verify that the sequence of requests in T does not exercise p. Therefore T is
inadequate with respect to the path coverage criterion.
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

491

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Consider the path p that begins execution at line 1, reaches the outermost while at

Example (contd.)

T’={<request=2, x=4>, <request=1, x=2, y=3>, <request=3>}

When the values in T' are input to our example program in the sequence given, the
program correctly outputs 24 as the factorial of 4 but incorrectly outputs 192 as the value
of 23 .
This happens because T' traverses our “tricky” path which makes the computation of the
exponentiation begin without initializing product. In fact the code at line 14 begins with
the value of product set to 24.
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

492

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

To cover p we construct the following test:

Contents Foundations of Software Testing 2E Author: Aditya P. Execution of the program under test on T' did cover a path that was not covered earlier and revealed an error in the program. Ltd Example (contd.) . Mathur 493 Copyright © 2013 Dorling Kindersley (India) Pvt.In our effort to increase the path coverage we constructed T' . This example has illustrated a benefit of test enhancement based on code coverage.

Copyright © 2013 Dorling Kindersley (India) Pvt.6 Single and multiple executions Contents Foundations of Software Testing 2E Author: Aditya P.1. Mathur 494 . Ltd 7.

one for each value of request. Mathur 495 Copyright © 2013 Dorling Kindersley (India) Pvt. Hence we consider T as a test set containing one test case and write it as follows: Contents Foundations of Software Testing 2E Author: Aditya P. Should T (or T’) be considered a single test or a sequence of three tests? T’={<request=2. x=4>. are input in a sequence during a single execution of the test program. Notice that both T . Ltd In the previous example we constructed two test sets T and T' . x=2. <request=1.Multiple executions and T' contain three tests one for each value of variable request. y=3>. <request=3>} we assumed that all three tests.

Multiple executions (contd.) We assumed that all three tests. it as follows: T”=T∪T’ Contents Foundations of Software Testing 2E Author: Aditya P. are input in a sequence Copyright © 2013 Dorling Kindersley (India) Pvt. one for each value of request. Ltd during a single execution of the test program. Mathur 496 . Hence we consider T as a test set containing one test case and write it.

Mathur 497 .Copyright © 2013 Dorling Kindersley (India) Pvt.2. Ltd 7.1 Statement and block coverage Contents Foundations of Software Testing 2E Author: Aditya P.

Notation: (P. such as the assignment. Ltd Any program written in a procedural language consists of a sequence of statements. Contents Foundations of Software Testing 2E Author: Aditya P. For any procedural language. adequacy with respect to the statement coverage and block coverage criteria are defined next. and while statements in C and Java. such as the #define and int statements in C. Mathur 498 Copyright © 2013 Dorling Kindersley (India) Pvt. . while others are executable. R) denotes program P subject to requirement R. Recall that a basic block is a sequence of consecutive statements that has exactly one entry point and one exit point. if.Declarations and basic blocks Some of these statements are declarative.

e. where . R) is 1. R ) is computed as Sc/(Se-Si) .Statement coverage Sc is the number of statements covered. Contents Foundations of Software Testing 2E Author: Aditya P. Si is the number of unreachable statements. the size of the coverage domain. and Se is the total number of statements in the program. i. Mathur 499 Copyright © 2013 Dorling Kindersley (India) Pvt. T is considered adequate with respect to the statement coverage criterion if the statement coverage of T with respect to (P. Ltd The statement coverage of T with respect to ( P.

Mathur 500 Copyright © 2013 Dorling Kindersley (India) Pvt. where Bc is the number of blocks covered. T is considered adequate with respect to the block coverage criterion if the statement coverage of T with respect to (P. Ltd Block coverage . i.e. the size of the block coverage domain. R) is 1. R) is computed as Bc/(Be -Bi) .The block coverage of T with respect to (P. Bi is the number of unreachable blocks. Contents Foundations of Software Testing 2E Author: Aditya P. and Be is the total number of blocks in the program.

Ltd Let T1={t1:<x=-1. R ) with respect to the statement coverage criterion. y=1>} . Si=1. Mathur 501 Copyright © 2013 Dorling Kindersley (India) Pvt. 5. 9. 3. 7b.Example: statement coverage Coverage domain: Se={2. Hence we conclude that T1 is adequate for (P. 4. 6. 4. y=-1>. and 10 t2: 2. Se=7. 7.t 2:<x=1. 10} Statements covered: t1: 2. 3. 9. Note: 7b is unreachable. 7. (b) Sc=6. Contents Foundations of Software Testing 2E Author: Aditya P. 4. 3. The statement coverage for T is 6/(7-1)=1 . 6. 5. and 10.

Hence T2 is not adequate for (P. 2. Ltd Coverage domain: Be={1. Block coverage for T2= 3/(5-1)=0. Bc=3. R) with respect to the block coverage criterion. Bi=1. 3. Mathur 502 Copyright © 2013 Dorling Kindersley (India) Pvt.Example: block coverage Blocks covered: t1: Blocks 1. 5 t2. 5 . 4. t3: same coverage as of t1. Contents Foundations of Software Testing 2E Author: Aditya P. 2. Be=5 .75.

) class exercise: Verify this statement! Also. if test t2 in T1 is added to T2.Example: block coverage (contd. Mathur 503 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd T1 is adequate w. block coverage criterion. In .r.t. In class exercise: Verify this statement! Contents Foundations of Software Testing 2E Author: Aditya P. we obtain a test set adequate with respect to the block coverage criterion for the program under consideration.

Contents Foundations of Software Testing 2E Author: Aditya P. However. Ltd The formulae given for computing various types of code coverage. a statement coverage of 0. while specifying a coverage value. one might instead use percentages.Coverage values Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 504 . For example. yield a coverage value between 0 and 1.65 is the same as 65% statement coverage.

Ltd 7.2 Conditions and decisions Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 505 .2.

true and false. x > y . x and x+y are valid conditions. Contents Foundations of Software Testing 2E Author: Aditya P. A . Note that in programming language C. respectively. are all sample conditions.Conditions Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 506 . and x and y are integers. A AND (x<y). Such an expression is also known as a predicate. (A AND B). A OR B . Ltd Any expression that evaluates to true or false constitutes a condition. Given that A . and B are Boolean variables. and the constants 1 and 0 correspond to.

≥. Simple conditions are also referred to as atomic or elementary conditions because they cannot be parsed any further into two or more conditions. ≠ }. ≤ >.Simple and compound conditions Copyright © 2013 Dorling Kindersley (India) Pvt. It is made up of variables and at most one relational operator from the set {<. ==. Mathur 507 . Contents Foundations of Software Testing 2E Author: Aditya P. Ltd A simple condition does not use any Boolean operators except for the not operator. A compound condition is made up of two or more simple conditions joined by one or more Boolean operators.

most . Mathur 508 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Any condition can serve as a decision in an appropriate context within a program. and switch statements to serve as contexts for decisions. Contents Foundations of Software Testing 2E Author: Aditya P.Conditions as decisions high level languages provide if. while.

When the .Outcomes of a decision condition corresponding to a decision to take one or the other path is taken. true. false. and undefined. Ltd A decision can have three possible outcomes. In some cases the evaluation of a condition might fail in which case the corresponding decision's outcome is undefined. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 509 Copyright © 2013 Dorling Kindersley (India) Pvt.

Contents Foundations of Software Testing 2E Author: Aditya P. Thus. Ltd Undefined condition . Mathur 510 Copyright © 2013 Dorling Kindersley (India) Pvt.The condition inside the if statement at line 6 will remain undefined because the loop at lines 2-4 will never terminate. the decision at line 6 evaluates to undefined.

The answer is four when one is interested in the number of occurrences of simple conditions in a compound condition. there are three distinct conditions A . Contents Foundations of Software Testing 2E Author: Aditya P. Does Cond contain three or four simple conditions? Both answers are correct depending on one's point of view. Mathur 511 Copyright © 2013 Dorling Kindersley (India) Pvt.How many simple conditions are there in the compound condition: Cond=(A AND B) OR (C AND A)? The first occurrence of A is said to be coupled to its second occurrence. B . Ltd Coupled conditions . Indeed. and C.

3 Decision coverage Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 7.2. Mathur 512 .

Mathur 513 . x<y does not constitute a decision and neither does A*B. Ltd appropriate context such as within an if statement.Conditions within assignments Strictly speaking. a condition becomes a decision only when it is used in the Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. At line 4.

Mathur 514 Copyright © 2013 Dorling Kindersley (India) Pvt. i. Ltd A decision is considered covered if the flow of control has been diverted to all .Decision coverage possible destinations that correspond to this decision.e. all outcomes of the decision have been taken. Contents Foundations of Software Testing 2E Author: Aditya P. This implies that. for example. the expression in the if or a while statement has evaluated to true in some execution of the program under test and to false in the same or another execution.

Decision coverage: switch statement

more executions of the program under test the flow of control has been diverted to all
possible destinations.

Covering a decision within a program might reveal an error that is not revealed by
covering all statements and all blocks.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

515

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

A decision implied by the switch statement is considered covered if during one or

This program inputs an integer x, and if necessary,
transforms it into a positive value before invoking
foo-1 to compute the output z. The program has an
error. As per its requirements, the program is
supposed to compute z using foo-2 when x≥0.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

516

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Decision coverage: Example

Consider the test set T={t1:<x=-5>}. It is adequate
with respect to statement and block coverage
criteria, but does not reveal the error.

Another test set T'={t1:<x=-5> t2:<x=3>} does
reveal the error. It covers the decision whereas T
does not. Check!

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

517

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Decision coverage: Example (contd.)

Decision coverage: Computation

revealing an error that is not revealed by a test set adequate with respect to statement
and block coverage.
The decision coverage of T with respect to ( P, R ) is computed as Dc/(De -Di) , where
Dc is the number of decisions covered, Di is the number of infeasible decisions, and
De is the total number of decisions in the program, i.e. the size of the decision coverage
domain.
T is considered adequate with respect to the decisions coverage criterion if the decision
coverage of T with respect to ( P, R ) is 1.
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

518

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

The previous example illustrates how and why decision coverage might help in

The domain of decision coverage consists of all decisions in the program under test.

Note that each if and each while contribute to one decision whereas a switch
contribute to more than one.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

519

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Decision coverage: domain

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

7.2.4 Condition coverage

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

520

Condition coverage

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

A decision can be composed of a simple condition such as x<0 , or of a more
complex condition, such as (( x<0 AND y<0 ) OR ( p≥q )).
AND, OR, XOR are the logical operators that connect two or more simple
conditions to form a compound condition.
A simple condition is considered covered if it evaluates to true and false in one or
more executions of the program in which it occurs. A compound condition is
considered covered if each simple condition it is comprised of is also covered.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

521

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

7.2.5 Condition/decision coverage

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

522

Decision coverage is concerned with the coverage of decisions regardless of whether
or not a decision corresponds to a simple or a compound condition. Thus, in the
statement

there is only one decision that leads control to line 2 if the compound condition
inside the if evaluates to true. However, a compound condition might evaluate to true
or false in one of several ways.
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

523

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Decision and condition coverage

The condition at line 1 evaluates to false when x≥0 regardless of the value of y.
Another condition, such as x<0 OR y<0, evaluates to true regardless of the value of
y, when x<0.
With this evaluation characteristic in view, compilers often generate code that uses
short circuit evaluation of compound conditions.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

524

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Decision and condition coverage (contd)

Decision and condition coverage (contd)

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Here is a possible translation:

We now see two decisions, one corresponding to each simple condition in the if
statement.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

525

The condition coverage of T with respect to ( P, R ) is computed as Cc/(Ce -Ci) ,
where Cc is the number of simple conditions covered, Ci is the number of infeasible
simple conditions, and |Ce is the total number of simple conditions in the program, i.e.
the size of the condition coverage domain.
T is considered adequate with respect to the condition coverage criterion if the
condition coverage of T with respect to ( P, R ) is 1.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

526

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Condition coverage

An alternate formula where each simple condition contributes 2, 1, or 0 to Cc
depending on whether it is covered, partially covered, or not covered, respectively. is:

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

527

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Condition coverage: alternate formula

Condition coverage: Example

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Partial specifications for computing z:

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

528

Condition coverage: Example (contd.)

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Consider the test set:

Check that T is adequate with respect to the
statement, block, and decision coverage criteria
and the program behaves correctly against t1 and
t2.
Cc=1, Ce=2, Ci=0. Hence condition coverage for
T=0.5.
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

529

Condition coverage: Example (contd.)

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Add the following test case to T:
t3: <x=3, y=4>
Check that the enhanced test set T is adequate
with respect to the condition coverage criterion
and possibly reveals an error in the program.
Under what conditions will a possible error at
line 7 be revealed by t3?

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

530

Condition/decision coverage

imply that each simple condition within a compound condition has taken both
values true and false.
Condition coverage ensures that each component simple condition within a
condition has taken both values true and false.
However, as illustrated next, condition coverage does not require each decision to
have taken both outcomes. Condition/decision coverage is also known as branch
condition coverage.
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

531

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

When a decision is composed of a compound condition, decision coverage does not

Condition/decision coverage: Example

In class exercise: Confirm that T1 is adequate with respect to
to decision coverage but not condition coverage.
In class exercise: Confirm that T2 is adequate with respect to
condition coverage but not decision coverage.
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

532

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Consider the following program and two test sets.

Condition/decision coverage: Definition

+Dc)/((Ce -Ci) +(De-Di)) , where Cc is the number of simple conditions covered,
Dc is the number of decisions covered, Ce and De are the number of simple
conditions and decisions respectively, and Ci and Di are the number of infeasible
simple conditions and decisions, respectively.

T is considered adequate with respect to the multiple condition coverage criterion if
the condition coverage of T with respect to ( P, R ) is 1.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

533

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

The condition/decision coverage of T with respect to (P, R) is computed as (Cc

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Condition/decision coverage: Example

In class exercise: Check that the following test set is
adequate with respect to the condition/decision
coverage criterion.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

534

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

7.2.6 Multiple Condition coverage

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

535

Consider a compound condition with two or more simple conditions. Using condition
coverage on some compound condition C implies that each simple condition within C
has been evaluated to true and false.

However, does it imply that all combinations of the values of the individual simple
conditions in C have been exercised?

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

536

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Multiple condition coverage

Multiple condition coverage: Example Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 537 . The four possible combinations of the outcomes of these two simple conditions are enumerated in the table. Ltd Consider D=(A<B) OR (A>C) composed of two simple conditions A< B and A> C . Consider T: Check: Does T cover all four combinations? Check: Does T’ cover all four combinations? Contents Foundations of Software Testing 2E Author: Aditya P.

the total number of combinations to be covered is n ∑2 ki i=1 € Contents Foundations of Software Testing 2E Author: Aditya P. Each decision has several combinations of values of its constituent simple conditions. k2.Multiple condition coverage: Definition Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Suppose that the program under test contains a total of n decisions. Assume also that each decision contains k1. Thus. decision i will have a total of 2ki combinations. kn simple conditions. Mathur 538 . For example. ….

R ) is computed as Cc/(Ce Ci) . T is considered adequate with respect to the multiple condition coverage criterion if the condition coverage of T with respect to ( P. and Ce is the total number of combinations in the program. where Cc is the number of combinations covered.The multiple condition coverage of T with respect to ( P. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 539 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Multiple condition coverage: Definition (contd. Ci is the number of infeasible simple combinations. R ) is 1.) .

line 3 in the table. Mathur 540 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Consider the following program with specifications in the table.Multiple condition coverage: Example There is an obvious error in the program. computation of S for one of the four combinations. has been left out. .

Multiple condition coverage: Example (contd. Mathur 541 .) Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Is T adequate with respect to decision coverage? Multiple condition coverage? Does it reveal the error? Contents Foundations of Software Testing 2E Author: Aditya P.

) Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 542 . Does T’ reveal the error? Contents Foundations of Software Testing 2E Author: Aditya P.Multiple condition coverage: Example (contd. Ltd To improve decision coverage we add t3 to T and obtain T’.

Mathur 543 Copyright © 2013 Dorling Kindersley (India) Pvt. Does your test reveal the error? If yes.In class exercise: Construct a table showing the simple conditions covered by T’. Ltd Multiple condition coverage: Example (contd. then under what conditions? Contents Foundations of Software Testing 2E Author: Aditya P. Do you notice that some combinations of simple conditions remain uncovered? Now add a test to T’ to cover the uncovered combinations.) .

7 LCSAJ coverage Contents Foundations of Software Testing 2E Author: Aditya P.2. Mathur 544 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 7.

proceeds in pairs . Y. locations of the first and the last statements and Z is the location to which the statement at Y jumps. Mathur 545 Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Execution of sequential programs that contain at least one condition. An LCSAJ is represented as a triple (X. and terminated by a jump to the next such pair. executed one after the other. A Linear Code Sequence and Jump is a program unit comprised of a textual code sequence that terminates in a jump to the beginning of another code sequence and jump. respectively. Z) where X and Y are.Linear Code Sequence and Jump (LCSAJ) where the first element of the pair is a sequence of statements.

and then jumps to statement Z. Z) is traversed or covered or exercised. Y. Z) is a jump and Z may be program exit. we say that the LCSAJ (X. Contents Foundations of Software Testing 2E Author: Aditya P. follows through to statement Y.Consider this program. When control arrives at statement X. The last statement in an LCSAJ (X. Mathur 546 Copyright © 2013 Dorling Kindersley (India) Pvt. Y. Ltd Linear Code Sequence and Jump (LCSAJ) .

Ltd LCSAJ coverage: Example 1 . 6. Mathur 547 Copyright © 2013 Dorling Kindersley (India) Pvt. T covers all three LCSAJs.4. Contents Foundations of Software Testing 2E Author: Aditya P.7) and (7.t1 covers (1. exit) is executed. 8. exit). t2 covers (1.

Mathur 548 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd LCSAJ coverage: Example 2 In class exercise: Find all LCSAJs Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd LCSAJ coverage: Example 2 (contd. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 549 .Copyright © 2013 Dorling Kindersley (India) Pvt.) Verify: This set covers all LCSAJs.

LCSAJ coverage: Definition Copyright © 2013 Dorling Kindersley (India) Pvt. R) is . R) is computed as T is considered adequate with respect to the LCSAJ coverage criterion if the LCSAJ coverage of T with respect to (P. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd The LCSAJ coverage of a test set T with respect to (P. Mathur 550 .

8 Modified condition/decision coverage Contents Foundations of Software Testing 2E Author: Aditya P.2.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 7. Mathur 551 .

the maximum number of tests required to cover C is 2n . When a compound condition C contains n simple conditions. Contents Foundations of Software Testing 2E Author: Aditya P.Modified Condition/Decision (MC/DC) Coverage Obtaining multiple condition coverage might become expensive when there are many Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 552 . Ltd embedded simple conditions.

MC/DC coverage is a weaker criterion than the multiple condition coverage criterion. Thus.Compound conditions and MC/DC Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 553 . Contents Foundations of Software Testing 2E Author: Aditya P. Ltd MC/DC coverage requires that every compound condition in a program must be tested by demonstrating that each simple condition within the compound condition has an independent effect on its outcome.

Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 554 . Ltd MC/DC coverage: Simple conditions Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd 7.Copyright © 2013 Dorling Kindersley (India) Pvt.9 MC/DC adequate tests for compound conditions Contents Foundations of Software Testing 2E Author: Aditya P.2. Mathur 555 .

Ltd Let C=C1 and C2 and C3. The column labeled Test contains rows labeled by test case numbers t1 through t4 . Create a table with five columns and four rows. C1. Mathur 556 Copyright © 2013 Dorling Kindersley (India) Pvt. Label the . C3 and C.Generating tests for compound conditions columns as Test. Contents Foundations of Software Testing 2E Author: Aditya P. An optional column labeled “Comments” may be added. C2 . from left to right. The remaining entries are empty.

C2 . Mathur 557 . C3.Generating tests for compound conditions (contd.) Copyright © 2013 Dorling Kindersley (India) Pvt. and C from the table for simple conditions into columns C2. Ltd Copy all entries in columns C1 . Contents Foundations of Software Testing 2E Author: Aditya P. and C of the empty table.

Ltd Fill the first three rows in the column marked C1 with true and the last row with false.) Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 558 .Generating tests for compound conditions (contd. Contents Foundations of Software Testing 2E Author: Aditya P.

true.Fill the last row under columns labeled C2 . We now have a table containing MC/DC adequate tests for C=(C1 AND C2 AND C3) derived from tests for C=(C1 AND C2) . Mathur 559 Copyright © 2013 Dorling Kindersley (India) Pvt. and C with true. Ltd MC/DC coverage: Generating tests for compound conditions (contd. and false. Contents Foundations of Software Testing 2E Author: Aditya P. respectively.) . C3 .

) The procedure illustrated above can be extended to derive tests for any compound condition using tests for a simpler compound condition (solve Exercises 7.15 and 7.16). Mathur 560 .Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd MC/DC coverage: Generating tests for compound conditions (contd.

Mathur 561 . Ltd 7.Copyright © 2013 Dorling Kindersley (India) Pvt.2.10 Definition of MC/DC coverage Contents Foundations of Software Testing 2E Author: Aditya P.

the following requirements are met. •  Each decision in P has taken all possible outcomes. is considered adequate . Contents Foundations of Software Testing 2E Author: Aditya P.MC/DC coverage: Definition with respect to the MC/DC coverage criterion if upon the execution of P on each test in T. Ltd A test set T for program P written to meet requirements R. •  Each simple condition in P has taken both true and false values. •  Each simple condition within a compound condition C in P has been shown to independently effect the outcome of C. Mathur 562 Copyright © 2013 Dorling Kindersley (India) Pvt. •  Each block in P has been covered. This is the MC part of the coverage we discussed.

condition. The fourth requirement corresponds to ``MC" coverage. it is to be noted that conditions that are not part of a decision. With regard to the second requirement.Analysis coverage. the MC/DC coverage criterion is a mix of four coverage criteria based on the flow of control. Ltd The first three requirements above correspond to block. Contents Foundations of Software Testing 2E Author: Aditya P. respectively. Thus. Mathur 563 Copyright © 2013 Dorling Kindersley (India) Pvt. and decision . such as the one in the following statement A= (p<q) OR (x>y) are also included in the set of conditions to be covered.

) poses a problem.Analysis (contd. It is not possible to keep the first occurrence of A fixed while varying the value of its second occurrence. a condition such as (A AND B) OR (C AND A) . Ltd With regard to the fourth requirement. In such cases an adequate test set need only demonstrate the independent effect of any one occurrence of the coupled condition Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 564 Copyright © 2013 Dorling Kindersley (India) Pvt. Here the first occurrence of A is said to be coupled to its second occurrence.

Mathur 565 . denoted by MCc. ni denote the number of simple conditions Copyright © 2013 Dorling Kindersley (India) Pvt. . ei the number of simple conditions shown to have independent affect on the outcome of Ci. The MC coverage of T for program P subject to requirements R. Test set T is considered adequate with respect to the MC coverage if MCc=1 of T is 1. CN be the conditions in P..Adequacy Let C1. is computed as follows. Ltd in Ci . Contents Foundations of Software Testing 2E Author: Aditya P. C2.. and fi the number of infeasible simple conditions in Ci .

Contents Foundations of Software Testing 2E Author: Aditya P.2: Invoke fire-2 when (x<y) AND (z * z ≤ y) OR (current=``South").Example Copyright © 2013 Dorling Kindersley (India) Pvt. R1. Ltd Consider the following requirements: R1.3: Invoke fire-3 when none of the two conditions above is true. R1. Mathur 566 .1: Invoke fire-1 when (x<y) AND (z * z > y) AND (prev=``East"). R2: The invocation described above must continue until an input Boolean variable becomes true.

) Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 567 . Ltd Example (contd.

Mathur 568 . Ltd Example (contd.Copyright © 2013 Dorling Kindersley (India) Pvt.) Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd Verify that the following set T1 of four tests.Example (contd. and decision coverage criteria but not with respect to the condition coverage criterion. block. executed in the given order.) Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 569 . is adequate with respect to statement.

) Verify that the following set T2.Example (contd. Ltd to the condition coverage but not with respect to the multiple condition coverage criterion. is adequate with respect Copyright © 2013 Dorling Kindersley (India) Pvt. Note that sequencing of tests is important in this case! Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 570 . obtained by adding t5 to T1.

t7. Ltd with respect to MC/DC coverage criterion.) Verify that the following set T3. and t9 to T2 is adequate Copyright © 2013 Dorling Kindersley (India) Pvt. obtained by adding t6. Mathur 571 . Note again that sequencing of tests is important in this case (especially for t1 and t7)! Contents Foundations of Software Testing 2E Author: Aditya P. t8.Example (contd.

12 Error detection and MC/DC adequacy Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.2. Mathur 572 . Ltd 7.

Mixed: One or more simple conditions is missing and one or more Boolean operators is incorrect. For example. Mathur 573 Copyright © 2013 Dorling Kindersley (India) Pvt. For example.MC/DC adequacy and error detection Missing condition: One or more simple conditions is missing from a compound condition. Ltd We consider the following three types of errors. the correct condition is (x<y AND done) which has been coded as (x<y OR done). the correct condition should be (x<y AND z*x ≥ y AND d=``South") has been coded as (x<y OR z*x ≥ y). For example. Contents Foundations of Software Testing 2E Author: Aditya P. the correct condition should be (x<y AND done) but the condition coded is (done). . Incorrect Boolean operator: One or more Boolean operators is incorrect.

Example Suppose that condition C=C1 AND C2 AND C3 has been coded as C'=C1 AND C2. Four Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd tests that form an MC/DC adequate set are in the following table. Contents Foundations of Software Testing 2E Author: Aditya P. Verify that the following set of four tests is MC/DC adequate but does not reveal the error. Mathur 574 .

The examples also show that an MC/DC adequate test will likely reveal more errors than a decision or condition-coverage adequate test.Several examples in the book show that satisfying the MC/DC adequacy criteria does not necessarily imply that errors made while coding conditions will be revealed. Ltd MC/DC and condition coverage . Mathur 575 Copyright © 2013 Dorling Kindersley (India) Pvt. the examples do favor MC/DC over condition coverage. However.”) Contents Foundations of Software Testing 2E Author: Aditya P. (Note the emphasis on “likely.

Contents Foundations of Software Testing 2E Author: Aditya P. or requires as in C. short circuit evaluation. or the combination C1=false and C2=false may be infeasible if the programming language allows. the combination C1=false and C2=true. The outcome of the above condition does not depend on C2 when C1 is false. Thus. Ltd MC/DC and short circuit evaluation . Mathur 576 Copyright © 2013 Dorling Kindersley (India) Pvt. When using short-circuit evaluation. condition C2 is not evaluated if C1 evaluates to false.Consider C=C1 AND C2.

MC/DC and decision dependence Copyright © 2013 Dorling Kindersley (India) Pvt. for example. Infeasible condition A<5 Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 577 . Consider. the following sequence of statements. Ltd Dependence of one decision on another might also lead to an infeasible combination.

It may. In this case the second decision is not reachable due an error at line 3.Infeasibility and reachability not feasible and vice versa. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Note that infeasibility is different from reachability. A decision might be reachable but . however. In the sequence above. Consider the following sequence. both decisions are reachable but the second decision is not feasible. be feasible. Mathur 578 Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 579 .2. Ltd 7.15 Tracing test cases to requirements Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Contents Foundations of Software Testing 2E Author: Aditya P. It has the likelihood of revealing errors and ambiguities in the requirements. See example 7. Mathur 580 Copyright © 2013 Dorling Kindersley (India) Pvt. it is desirable to ask the . Advantages of trace back: Assists us in determining whether or not the new test case is redundant. It assists with the process of documenting tests against requirements.27. Ltd When enhancing a test set to satisfy a given coverage criterion.Test trace back following question: What portions of the requirements are tested when the program under test is executed against the newly added test case? The task of relating the new test case to the requirements is known as test trace-back.

3.Copyright © 2013 Dorling Kindersley (India) Pvt.3 Concepts from data flow 7.1 Definitions and uses Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 7. Mathur 581 .

Mathur 582 .Basic concepts Copyright © 2013 Dorling Kindersley (India) Pvt. This is in contrast to criteria based on “flow of control” that we have examined so far. Let us look at an example. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd We will now examine some test adequacy criteria based on the flow of “data” in a program. Test adequacy criteria based on the flow of data are useful in improving tests that are adequate with respect to control-flow based criteria.

Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Here is an MC/DC adequate test set that does not reveal the error.Example: Test enhancement using data flow Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 583 .

Example (contd. Mathur Contents 584 Copyright © 2013 Dorling Kindersley (India) Pvt. at line 9. An MC/DC adequate test does not force the execution of this path and hence the divide by zero error is not revealed. Ltd Neither of the two tests force the use of z defined on .) line 6. To do so one requires a test that causes conditions at lines 5 and 8 to be true. Foundations of Software Testing 2E Author: Aditya P.

Example (contd. Ltd error. Would an LCSAJ adequate test also reveal the error? Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 585 .) Verify that the following test set covers all def-use pairs of z and reveals the Copyright © 2013 Dorling Kindersley (India) Pvt.

Statement x=y+z defines variable x and uses variables y and z. Declaration int x. contains variables.Definitions and uses Copyright © 2013 Dorling Kindersley (India) Pvt. &x. Statement printf(``Output: %d \n". &y) defines variables x and y. y. Ltd A program written in a procedural language. A[10]. Variables are defined by assigning values to them and are used in expressions. x+y) uses variables x and y. Contents Foundations of Software Testing 2E Author: Aditya P. such as C and Java. defines three variables. Statement scanf(``%d %d". Mathur 586 .

Mathur 587 .) A parameter x passed as call-by-value to a function. x.Copyright © 2013 Dorling Kindersley (India) Pvt. A parameter x passed as call-by-reference. serves as a definition and use of x Contents Foundations of Software Testing 2E Author: Aditya P. is considered as a use of. Ltd Definitions and uses (contd. or a reference to.

Definitions and uses: Pointers Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Consider the following sequence of statements that use pointers. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 588 . The first of the above statements defines a pointer variable z the second defines y and uses z the third defines x through the pointer variable z and the last defines y and uses x accessed through the pointer variable z.

The choice of whether to consider the entire array A as defined or the specific element depends upon how stringent is the requirement for coverage analysis.Definitions and uses: Arrays The first statement defines variable A. x. The second statement defines A and uses i . Ltd Arrays are also tricky. Mathur 589 Copyright © 2013 Dorling Kindersley (India) Pvt. Alternate: second statement defines A[i] and not the entire array A. Contents Foundations of Software Testing 2E Author: Aditya P. and y. Consider the following declaration and two statements in C: .

2 C-use and p-use Contents Foundations of Software Testing 2E Author: Aditya P.3. Mathur 590 . Ltd 7.Copyright © 2013 Dorling Kindersley (India) Pvt.

c-use Copyright © 2013 Dorling Kindersley (India) Pvt. are classified as c-use. as a parameter within a function call. Mathur 591 . Ltd Uses of a variable that occur within an expression as part of an assignment statement. where the ``c" in c-use stands for computational. in an output statement. and in subscript expressions. How many c-uses of x can you find in the following statements? Answer: 5 Contents Foundations of Software Testing 2E Author: Aditya P.

The ``p" in p-use stands for predicate. How many p-uses of z and x can you find in the following statements? Answer: 3 (2 of z and 1 of x) Contents Foundations of Software Testing 2E Author: Aditya P.p-use The occurrence of a variable in an expression used as a condition in a branch Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd statement such as an if and a while. Mathur 592 . is considered as a p-use.

Contents Foundations of Software Testing 2E Author: Aditya P. Is the use of x in the subscript.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 593 . a c-use or a p-use? Discuss. Ltd p-use: possible confusion Consider the statement: The use of A is clearly a p-use.

their definitions flow into this block from some other block. The first definition of p is considered local to the block while the second definition is global.C-uses within a basic block Copyright © 2013 Dorling Kindersley (India) Pvt. and uses. Mathur 594 . Ltd Consider the basic block While there are two definitions of p in this block. Contents Foundations of Software Testing 2E Author: Aditya P. Note that y and z are global uses. only the second definition will propagate to the next block. We are concerned with global definitions.

4 Data flow graph Contents Foundations of Software Testing 2E Author: Aditya P.3. Mathur 595 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 7.

captures the flow of definitions (also known as defs) across basic blocks in a program. Mathur 596 . edges. An example follows.Data flow graph Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd A data-flow graph of a program. It is similar to a control flow graph of a program in that the nodes. and all paths thorough the control flow graph are preserved in the data flow graph. also known as def-use graph.

We use di(x) to refer to the definition of variable x at node i. Each block becomes a node in the def-use graph (this is similar to the control flow graph). Ltd Given a program. find its basic blocks. Mathur 597 Copyright © 2013 Dorling Kindersley (India) Pvt. c-use and p-use to each node in the graph. Attach defs. c-uses and p-uses in each . Contents Foundations of Software Testing 2E Author: Aditya P. ui(x) refers to the use of variable x at node i. Similarly. Label each edge with the condition which when true causes the edge to be taken. compute defs.Example block.

Ltd Example (contd. Mathur 598 .) Unreachable node Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 599 .3.Copyright © 2013 Dorling Kindersley (India) Pvt.5 Def-clear paths Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 7.

Mathur 600 . Contents Foundations of Software Testing 2E Author: Aditya P. Thus. Path 2-5 is def-clear for variable z defined at node 2 and used at node 5. is a def-clear path for x. definition of z at node 2 is live at node 5 while that at node 1 is not live at node 5. without redefining x anywhere else along the path. Ltd defined and ending at a node at which x is used.Def-clear path Any path starting from a node at which variable x is Copyright © 2013 Dorling Kindersley (India) Pvt. Path 1-2-5 is NOT def-clear for variable z defined at node 1 and used at node 5.

Which definitions are live at node 4? Foundations of Software Testing 2E Author: Aditya P.Def-clear path (another example) Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 601 Contents . Ltd P7.16 Find def-clear paths for defs and uses of x and z.

Ltd 7.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 602 .3.6 def-use pairs Contents Foundations of Software Testing 2E Author: Aditya P.

We say that a def-use pair (di(x). k) must also be taken during some executions. Mathur 603 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Def of a variable at line l1 and its use at line l2 constitute a def-use pair. l) such that there is a def-clear path from node i to edge (k. l) and x is used at node k. uj(x)) is covered when a def-clear path that includes nodes i to node j is executed. dpu (di(x)) denotes the set of all edges (k. dcu (di(x)) denotes the set of all nodes where di(x)) is live and used. If uj(x)) is a p-use then all edges of the kind (j. Contents Foundations of Software Testing 2E Author: Aditya P. l1 and l2 .Def-use pairs can be the same.

Mathur 604 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Def-use pairs (example) Contents Foundations of Software Testing 2E Author: Aditya P.

Analysis of the data flow graph can reveal a minimal set of def-use pairs whose coverage implies coverage of all def-use pairs. Contents Foundations of Software Testing 2E Author: Aditya P. in some cases.Def-use pairs: Minimal set of a def-use pair implies coverage of another def-use pair. Exercise: Analyze the def-use graph shown in the previous slide and determine a minimal set of def-uses to be covered. Ltd Def-use pairs are items to be covered during testing. Mathur 605 Copyright © 2013 Dorling Kindersley (India) Pvt. coverage . However.

Given a total of n variables v1. PU: total number of p-uses. Ltd CU: total number of c-uses in a program.Data flow based adequacy Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 606 . Contents Foundations of Software Testing 2E Author: Aditya P. v2…vn each defined at di nodes.

4.4 Adequacy criteria based on data flow 7. c-use coverage Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 607 .Copyright © 2013 Dorling Kindersley (India) Pvt.1. Ltd 7.

Ltd C-use coverage Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 608 .Copyright © 2013 Dorling Kindersley (India) Pvt.

.. End) covers the c-use at node z of x defined at node q given that (k …. q. .... z. . z) is def clear with respect to x Exercise: Find the c-use coverage when program c-use of x P7. y=-1.Path (Start. count=1> Contents Foundations of Software Testing 2E Author: Aditya P. Ltd C-use coverage: path traversed .16 is executed against the following test: t1: <x=5. Mathur 609 Copyright © 2013 Dorling Kindersley (India) Pvt. k.

4. Mathur 610 . Ltd 7.4 Adequacy criteria based on data flow 7.Copyright © 2013 Dorling Kindersley (India) Pvt.2 p-use coverage Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd p-use coverage Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 611 .

16 is executed against the following test: t2: <x=-2. count=3> Contents Foundations of Software Testing 2E Author: Aditya P. y=-1.Exercise: Find the p-use coverage when program P7. Mathur 612 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd p-use coverage: paths traversed .

4. Mathur 613 . all-uses coverage Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 7.Copyright © 2013 Dorling Kindersley (India) Pvt.4 Adequacy criteria based on data flow 7.3.

Copyright © 2013 Dorling Kindersley (India) Pvt.r. t2} adequate w.t. Ltd All-uses coverage Exercise: Is T={t1. to all-uses coverage for P7. Mathur 614 .16? Contents Foundations of Software Testing 2E Author: Aditya P.

Contents Foundations of Software Testing 2E Author: Aditya P. if this path is infeasible. Mathur 615 .or a p-use requires a path to be traversed through the program.Copyright © 2013 Dorling Kindersley (India) Pvt. then some c.and p-uses that require this path to be traversed might also be infeasible. However. Infeasible uses are often difficult to determine without some hint from a test tool. Ltd Infeasible p.and c-uses Coverage of a c.

Contents Foundations of Software Testing 2E Author: Aditya P.Consider the c-use at node 4 of z defined at node 5. Ltd Infeasible c-use: Example . Show that this c-use is infeasible. Mathur 616 Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 617 .4 k-dr chain coverage Contents Foundations of Software Testing 2E Author: Aditya P. Ltd 7.4.Copyright © 2013 Dorling Kindersley (India) Pvt.

Other data-flow based criteria Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 618 . Ltd There exist several other adequacy criteria based on data flows. (b) Data context and ordered data context coverage. These are alternating sequences of def-use for one or more variables. and all-uses criteria. Some of these are more powerful in their error-detection effectiveness than the c-. Examples: (a) def-use chain or k-dr chain coverage. p-. Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd 7.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 619 .6 The “subsumes” relation Contents Foundations of Software Testing 2E Author: Aditya P.

Subsumes: Given a test set T that is adequate with respect to criterion C1. what can we expect regarding its effectiveness in revealing errors? Contents Foundations of Software Testing 2E Author: Aditya P. what can we conclude about the adequacy of T with respect to another criterion C2? Effectiveness: Given a test set T that is adequate with respect to criterion C. Mathur 620 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Subsumes relation .

Ltd Subsumes relationship Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 621 .

Data flow based: c-use. condition. multiple condition. Mathur 622 . Control flow based: statement. Ltd We have introduced the notion of test adequacy and enhancement. and LCSAJ coverage. data context. Many more exist. Contents Foundations of Software Testing 2E Author: Aditya P. p-uses. k-dr chain. MC/DC. decision.Summary Copyright © 2013 Dorling Kindersley (India) Pvt. Two types of adequacy criteria considered: one based on control flow and the other on data flow. elementary data context. all-uses. Many more exist.

Several test organizations believe that code coverage is useful at unit-level. Incremental assessment of code coverage and enhancement of tests can allow the application of coverage-based testing to large programs. such as PaRTe. Mathur 623 Copyright © 2013 Dorling Kindersley (India) Pvt. Cobertura. This is a myth and needs to be shattered.) during testing and displays it in a user-friendly manner. are available.Summary (contd. and Bullseye. Ltd Use of any of the criteria discussed here requires a test tool that measures coverage . xSUDS is one such set of tools. Several other commercial tools. Contents Foundations of Software Testing 2E Author: Aditya P.

Mathur 624 Copyright © 2013 Dorling Kindersley (India) Pvt.) . Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Summary (contd.Even though coverage is not guaranteed to reveal all program errors. Tests derived using black-box approaches can almost always be enhanced using one or more of the assessment criteria discussed. it is the perhaps the most effective way to assess the amount of code that has been tested and what remains untested.

Ltd Chapter 8 Test Adequacy Measurement and Enhancement Using Mutation Updated: July 18. Mathur 625 .Copyright © 2013 Dorling Kindersley (India) Pvt. 2013 Foundations of Software Testing 2E Contents Author: Aditya P.

Learning Objectives What is test adequacy? What is test enhancement? When to measure test Copyright © 2013 Dorling Kindersley (India) Pvt. §  Strengths and limitations of test adequacy based on program mutation. Ltd §  adequacy and how to use it to enhance tests? §  What is program mutation? §  Competent programmer hypothesis and the coupling effect. §  Mutation operators §  Tools for mutation testing Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 626 .

Let R contain n requirements labeled R1. R2. or as: Is T adequate? Contents Foundations of Software Testing 2E Author: Aditya P. Also. Mathur 627 Copyright © 2013 Dorling Kindersley (India) Pvt. R). §  Suppose now that a set T containing k tests has been constructed to test P to determine whether or not it meets all the requirements in R . §  We now ask: Is T good enough? This question can be stated differently as: Has P been tested thoroughly?.What is adequacy? Consider a program P written to meet a set R of functional requirements. Rn . P has been executed against each test in T and has produced correct behavior. We notate such a P and R as ( P.…. Ltd §  .

Now suppose we do the following: Changed to P P’ What behavior do you expect from P’ against tests in T? Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 628 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd What is program mutation? .§  Suppose that program P has been tested against a test set T and P has not failed on any test case in T.

Mathur 629 Copyright © 2013 Dorling Kindersley (India) Pvt.§  P’ is known as a mutant of P. In this case we say that t distinguishes P’ from P. §  There might be a test t in T such that P(t)≠P’(t). Ltd What is program mutation? [2] . In this case we say that T is unable to distinguish P and P’. Contents Foundations of Software Testing 2E Author: Aditya P. that t has killed P’. Hence P’ is considered live in the test process. Or. §  There might be not be any test t in T such that P(t)≠P’(t).

We will refer to program mutation as mutation. §  A non-equivalent and live mutant offers the tester an opportunity to generate a new test case and hence enhance T. Mathur 630 Copyright © 2013 Dorling Kindersley (India) Pvt.§  If there does not exist any test case t in the input domain of P that distinguishes P from P’ then P’ is said to be equivalent to P. Ltd What is program mutation? [3] . §  If P’ is not equivalent to P but no test in T is able to distinguish it from P then T is considered inadequate. Contents Foundations of Software Testing 2E Author: Aditya P.

§ 

Given a test set T for program P that must meet requirements R, a test adequacy
assessment procedure proceeds as follows.

§ 

Step 1: Create a set M of mutants of P. Let M={M0, M1…Mk}. Note that we have
k mutants.

§ 

Step 2: For each mutant Mi find if there exists a t in T such that Mi(t) ≠P(t). If
such a t exists then Mi is considered killed and removed from further
consideration.
Contents

Foundations of Software Testing 2E

Author: Aditya P. Mathur

631

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Test adequacy using mutation [1]

§ 

Step 3: At the end of Step 2 suppose that k1 ≤ k mutants have been killed and (kk1) mutants are live.
Case 1: (k-k1)=0: T is adequate with respect to mutation.
Case 2: (k-k1)>0 then we compute the mutation score (MS) as follows:
MS=k1/(k-e)
where e is the number of equivalent mutants. Note: e ≤ (k-k1).
Contents

Foundations of Software Testing 2E

Author: Aditya P. Mathur

632

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Test adequacy using mutation [2]

§ 

One has the opportunity to enhance a test set T after having assessed its
adequacy.

§ 

Step 1: If the mutation score (MS) is 1, then some other technique, or a different
set of mutants, needs to be used to help enhance T.

§ 

Step 2: If the mutation score (MS) is less than 1, then there exist live mutants that
are not equivalent to P. Each live mutant needs to be distinguished from P.
Contents

Foundations of Software Testing 2E

Author: Aditya P. Mathur

633

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Test enhancement using mutation

§ 

Step 3: Hence a new test t is designed with the objective of distinguishing at least
one of the live mutants; let us say this mutant is m.

§ 

Step 4: If t does not distinguish m then another test t’ needs to be designed to
distinguish m. Suppose that t does distinguish m.

§ 

Step 5: It is possible that t also distinguishes other live mutants.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

634

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Test enhancement using mutation [2]

§ 

Step 6: Add t to T and re-compute the mutation score (MS).

§ 

Repeat the enhancement process from Step 1.

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Test enhancement using mutation [3]

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

635

§ 

As with any test enhancement technique, there is no guarantee that tests derived
to distinguish live mutants will reveal a yet undiscovered error in P. Nevertheless,
empirical studies have found to be the most powerful of all formal test
enhancement techniques.

§ 

The next simple example illustrates how test enhancement using mutation detects
errors.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

636

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Error detection using mutation

§ 

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Error detection using mutation [2]

Consider the following function foo that is required to return the sum of two
integers x and y. Clearly foo is incorrect.
int foo(int x, y){
return (x-y);

This should be return (x+y)

}

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

637

§ 

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Error detection using mutation [3]

Now suppose that foo has been tested using a test set T that contains two tests:
T={ t1: <x=1, y=0>, t2: <x=-1, y=0>}

§ 

First note that foo behaves perfectly fine on each test in, i.e. foo returns the
expected value for each test case in T. Also, T is adequate with respect to all
control and data flow based test adequacy criteria.
Contents

Foundations of Software Testing 2E

Author: Aditya P. Mathur

638

Error detection using mutation [4]

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Let us evaluate the adequacy of T using mutation. Suppose that the following
three mutants are generated from foo.
M1: int foo(int x, y){

§ 

M2: int foo(int x, y){

M3: int foo(int x, y){

return (x+y);

return (x-0);

return (0+y);

}

}

}

Note that M1 is obtained by replacing the - operator by a + operator, M2 by
replacing y by 0, and M3 by replacing x by 0.
Contents

Foundations of Software Testing 2E

Author: Aditya P. Mathur

639

Error detection using mutation [4]
Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Next we execute each mutant against tests in T until the mutant is distinguished
or we have exhausted all tests. Here is what we get.
T={ t1: <x=1, y=0>, t2: <x=-1, y=0>}
Test (t)

foo(t)

M1(t)

M2(t)

M3(t)

t1

1

1

1

0

t2

-1

-1

-1

0

Live

Live

Killed
Contents

Foundations of Software Testing 2E

Author: Aditya P. Mathur

640

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Error detection using mutation [5]
After executing all three mutants we find that two are live and one is
distinguished. Computation of mutation score requires us to determine of any of
the live mutants is equivalent.

In class exercise: Determine whether or not the two live mutants are equivalent
to foo and compute the mutation score of T.

Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

641

Error detection using mutation [6]

M1: int foo(int x, y){

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Let us examine the following two live mutants.
M2: int foo(int x, y){

return (x+y);

return (x-0);

}

}

Let us focus on M1. A test that distinguishes M1 from foo must
satisfy the following condition:
x-y≠x+y implies y ≠0.
Hence we get t3: <x=1, y=1>
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

642

Error detection using mutation [7]

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Executing foo on t3 gives us foo(t3)=0. However, according to the requirements
we must get foo(t3)=2. Thus, t3 distinguishes M1 from foo and also reveals
the error.
M1: int foo(int x, y){

M2: int foo(int x, y){

return (x+y);

return (x-0);

}

}

In class exercise: (a) Will any test that distinguishes also reveal the error? (b)
Will any test that distinguishes M2 reveal the error?
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

643

Guaranteed error detection

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd

Sometimes there exists a mutant P’ of program P such that any test t that
distinguishes P’ from P also causes P to fail. More formally:
Let P’ be a mutant of P and t a test in the input domain of P. We say
that P’ is an error revealing mutant if the following condition holds
for any t.
P’(t) ≠P(t) and P(t) ≠R(t), where R(t) is the expected response of P
based on its requirements.
Is M1 in the previous example an error revealing mutant? What about
M2?
Contents
Foundations of Software Testing 2E

Author: Aditya P. Mathur

644

then Sin≠ Sout. Mathur 645 .Distinguishing a mutant Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd A test case t that distinguishes a mutant m from its parent program P program must satisfy the following three conditions: Condition 1: Reachability: t must cause m to follow a path that arrives at the mutated statement in m. Contents Foundations of Software Testing 2E Author: Aditya P. Condition 2: Infection: If Sin is the state of the mutant upon arrival at the mutant statement and Sout the state soon after the execution of the mutated statement.

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Distinguishing a mutant [2] Condition 3: Propagation: If difference between Sin and Sout must propagate to the output of m such that the output of m is different from that of P. Contents Foundations of Software Testing 2E Author: Aditya P. Exercise: Show that in the previous example both t1 and t2 satisfy the above three conditions for M3. Mathur 646 .

Contents Foundations of Software Testing 2E Author: Aditya P.Equivalent mutants The problem of deciding whether or not a mutant is equivalent to its Copyright © 2013 Dorling Kindersley (India) Pvt. empirical studies have shown that one can expect about 5% of the generated mutants to the equivalent to the parent program. Hence there is no way to fully automate the detection of equivalent mutants. However. Ltd •  parent program is undecidable. •  The number of equivalent mutants can vary from one program to another. Mathur 647 . •  Identifying equivalent mutants is generally a manual and often time consuming--as well as frustrating--process.

Ltd able to detect errors due to missing path. Consider the following programs. y){ int p=0. if(x<y) Missing else Copyright © 2013 Dorling Kindersley (India) Pvt. p=p+1. if(x<y) p=p+1.A misconception There is a widespread misconception amongst testing educators. y){ Correct program int foo(int x. return(x+p*y) else } p=p-1. int p=0. return(x+p*y) } Foundations of Software Testing 2E Author: Aditya P. and practitioners that any “coverage” based technique. Mathur Contents 648 . including mutation. researchers. will not be Program under test int foo(int x.

Is T guaranteed to reveal the error? (c) Suppose T is def-use adequate for foo. Ltd (a)  Suggest at least one mutant M of foo that is guaranteed to reveal the error. Is T guaranteed to reveal the error? Contents Foundations of Software Testing 2E Author: Aditya P. in other words M is an error revealing mutant. (b) Suppose T is decision adequate for foo.A misconception [2] Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 649 .

•  Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 650 . Mk Contents Foundations of Software Testing 2E Author: Aditya P. M1 O(P) M2 …. Ltd Mutant operators A mutant operator O is a function that maps the program under test to a set of k (zero or more) mutants of P.

Ltd Mutant operators [2] A mutant operator creates mutants by making simple changes in the program under test. Contents Foundations of Software Testing 2E Author: Aditya P. An “relational operator replacement” mutant operator replaces relational operator wirh another relational operator. •  For example. Mathur 651 .•  Copyright © 2013 Dorling Kindersley (India) Pvt. the “variable replacement” mutant operator replaces a variable name by another variable declared in the program.

Relational operator replacement if (x<y) if(x>y) if(x<=y) Off-by-1 z=x*y+1. z=0. z=x+y-1. x=x*y+1. Arithmetic operator replacement z=x*y+1. Mathur 652 . z=0*y+1. z=(x+1)*y+1. Ltd Mutant operator Contents Foundations of Software Testing 2E Author: Aditya P. z=x*(y+1)+1.Mutant operators: Examples In P In mutant Variable replacement z=x*y+1. z=x*x+1. Copyright © 2013 Dorling Kindersley (India) Pvt. Replacement by 0 z=x*y+1. z=x*y-1.

a second order mutant of z=x+y.Mutants: First order and higher order •  A mutant obtained by making exactly “one change” is considered first •  Copyright © 2013 Dorling Kindersley (India) Pvt. Similarly higher order mutants can be defined. Mathur 653 . •  In practice only first order mutants are generated for two reasons: (a) to lower the cost of testing and (b) most higher order mutants are killed by tests adequate with respect to first order mutants. [See coupling effect later. where the variable replacement operator has been applied twice.] Contents Foundations of Software Testing 2E Author: Aditya P. is x=z+y. For example. A mutant obtained by making two changes is a second order mutant. Ltd order.

Mathur 654 . mutant operators model simple mistakes. Ltd •  programmer •  Several error studies have revealed that programmers--novice and experts--make simple mistakes. •  While programmers make “complex mistakes” too. As we shall see later.Mutant operators: basis A mutant operator models a simple mistake that could be made by a Copyright © 2013 Dorling Kindersley (India) Pvt. For example. Contents Foundations of Software Testing 2E Author: Aditya P. the “coupling effect” explains why only simple mistakes are modeled. instead of using x<y+1 one might use x<y.

Contents Foundations of Software Testing 2E Author: Aditya P. we say that S1 is superior to S2 if mutants generated using S1 guarantee a larger number of errors detected over a set of erroneous programs. Based on the effectiveness criteria. Mathur 655 . It Copyright © 2013 Dorling Kindersley (India) Pvt.Mutant operators: Goodness •  The design of mutation operators is based on guidelines and experience. How should we judge whether or not that a set of mutation operators is “good enough?” •  Informal definition: •  Let S1 and S2 denote two sets of mutation operators for language L. evident that two groups might arrive at a different set of mutation operators for the same programming language. Ltd is Thus.

We say that one is using “constrained” or “selective” mutation when one uses this small set of mutation operators. Ltd •  rather than the complete set of operators.Mutant operators: Goodness [2] Generally one uses a small set of highly effective mutation operators Copyright © 2013 Dorling Kindersley (India) Pvt. •  Experiments have revealed relatively small sets of mutation operators for C and Fortran. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 656 .

Ada. and Java. Lisp. •  Languages differ in their syntax thereby offering opportunities for making Copyright © 2013 Dorling Kindersley (India) Pvt. [See the text for a comparison of mutant operators across several languages.] Contents Foundations of Software Testing 2E Author: Aditya P.•  For each programming language one develops a set of mutant operators. This leads to differences in the set of mutant operators for two languages. •  Mutant operators have been developed for languages such as Fortran. C. Mathur 657 . Ltd Mutant operators: Language dependence mistakes that duffer between two languages.

a programmer writes a program P that is in the general neighborhood of the set of correct programs. a programmer is unlikely to write a program that deposits money into an account. given an account number. Mathur 658 . while such a situation is unlikely to arise. a devious programmer might certainly write such a program. Of course. Ltd Competent programmer hypothesis (CPH) CPH states that given a problem statement.•  Copyright © 2013 Dorling Kindersley (India) Pvt. •  An extreme interpretation of CPH is that when asked to write a program to find the account balance. Contents Foundations of Software Testing 2E Author: Aditya P.

will find one prior to writing the program. and if not. •  It is Thus. •  The CPH assumes that the programmer knows of an algorithm to solve the problem at hand. at least one sorting algorithm. a competent programs knows of. Ltd •  to satisfy a set of requirements will be a few mutants away from a correct program. Mathur 659 .Competent programmer hypothesis (CPH) [2] A more reasonable interpretation of the CPH is that the program written Copyright © 2013 Dorling Kindersley (India) Pvt. safe to assume that when asked to write a program to sort a list of numbers. Contents Foundations of Software Testing 2E Author: Aditya P. and makes use of. Mistakes will lead to a program that can be corrected by applying one or more first order mutations.

" Contents Foundations of Software Testing 2E Author: Aditya P. Ltd •  Sayward as follows: “Test data that distinguishes all programs differing from a correct one by only simple errors is so sensitive that it also implicitly distinguishes more complex errors” •  Stated alternately. Mathur 660 .seemingly simple tests can be quite sensitive via the coupling effect. and Copyright © 2013 Dorling Kindersley (India) Pvt. Lipton.. again in the words of DeMillo. Lipton and Sayward ``.Coupling effect The coupling effect has been paraphrased by DeMillo.

This perturbation takes place at the point of mutation and has the potential of infecting the entire state of the program. a non-equivalent mutant forces a slight perturbation in Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 661 . Ltd •  the state space of the program under test.Coupling effect [2] For some input. •  It is during an analysis of the behavior of the mutant in relation to that of its parent that one discovers complex faults. Contents Foundations of Software Testing 2E Author: Aditya P.

Tools for mutation testing As with any other type of test adequacy assessment. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 662 . Two such tools are Proteum for C from Professor Josè Maldonado and muJava for Java from Professor Jeff Offutt. See the textbook for a more complete listing of mutation tools. Ltd •  assessment must be done with the help of a tool. mutation based Copyright © 2013 Dorling Kindersley (India) Pvt. We are not aware of any commercially available tool for mutation testing. •  There are few mutation testing tools available freely.

§  A selectable palette of mutation operators. Mathur 663 . Ltd •  comparison against that of mutants.Tools for mutation testing: Features A typical tool for mutation testing offers the following features. §  Generation of mutants. Contents Foundations of Software Testing 2E Author: Aditya P. §  Execution of the program under test against T and saving the output for Copyright © 2013 Dorling Kindersley (India) Pvt. §  Management of test set T.

Contents Foundations of Software Testing 2E Author: Aditya P. an advanced mutation tool for Fortran also provided automatic test generation using DeMillo and Offutt’s method. allows the application of a subset of mutation operators to a portion of the program under test. §  Mothra. Mathur 664 . Ltd Tools for mutation testing: Features [2] Mutant execution and computation of mutation score using user identified equivalent mutants.§  Copyright © 2013 Dorling Kindersley (India) Pvt. §  Incremental mutation testing: i.e.

Contents Foundations of Software Testing 2E Author: Aditya P. §  The following procedure is recommended to assess the adequacy of system tests. given a good tool. §  However. Ltd §  relatively small units. e. a class in Java or a small collection of functions in C.Mutation and system testing Adequacy assessment using mutation is often recommended only for Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 665 . one can use mutation to assess adequacy of system tests.g.

This selection is best guided by the operators defined by Eric Wong or Jeff Offutt. Repeat the following steps for each unit in U.Mutation and system testing [2] Step 1: Identify a set U of application units that are critical to the safe and Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd §  secure functioning of the application. §  Step 2: Select a small set of mutation operators. [See the text for details. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 666 .] §  Step 3: Apply the operators to the selected unit.

use of a limited set of highly effective mutation operators). and perhaps enhanced it. Mathur 667 Copyright © 2013 Dorling Kindersley (India) Pvt. §  We have now assessed T.. Contents Foundations of Software Testing 2E Author: Aditya P.e. enhance T. Ltd Mutation and system testing [3] . §  Step 5: Repeat Steps 3 and 4 for the next unit until all units have been considered.§  Step 4: Assess the adequacy of T using the mutants so generated. Note the use of incremental testing and constrained mutation (i. If necessary.

and other advanced test assessment and enhancement techniques. security. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 668 . Ltd Mutation and system testing [4] Application of mutation. is recommended for applications that must meet stringent availability.§  Copyright © 2013 Dorling Kindersley (India) Pvt. safety requirements.

Mathur 669 . as with any other test assessment technique. §  Identification of equivalent mutants is an undecidable problem--similar the identification of infeasible paths in control or data flow based test assessment.Summary Mutation testing is the most powerful technique for the assessment and Copyright © 2013 Dorling Kindersley (India) Pvt. §  Mutation. Ltd §  enhancement of tests. must be applied incrementally and with assistance from good tools. Contents Foundations of Software Testing 2E Author: Aditya P.

when done Copyright © 2013 Dorling Kindersley (India) Pvt. secure. it can be used for the assessment of system and other types of tests applied to an entire application. Ltd §  carefully and incrementally. Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 670 . and safe systems.Summary [2] While mutation testing is often recommended for unit testing. §  Mutation is a highly recommended technique for use in the assurance of quality of highly available.

Minimization. Ltd Chapter 9 . and Prioritization for Regression Testing Updated: July 17. Mathur 671 Copyright © 2013 Dorling Kindersley (India) Pvt.Test Selection. 2013 Foundations of Software Testing 2E Contents Author: Aditya P.

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Learning Objectives What is regression testing? How to select a subset of tests for regression testing? How to select or minimize a set of tests for regression testing? How to prioritize a set of tests for regression testing? Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 672 .

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 9.1. Mathur 673 . What is regression testing? Contents Foundations of Software Testing 2E Author: Aditya P.

Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 674 . Ltd Regression testing Contents Foundations of Software Testing 2E Author: Aditya P.

[This is the TEST-ALL approach. Ltd What tests to use? Idea 1: All valid tests from the previous version and new tests created to test any added functionality.] What are the strengths and shortcomings of this approach? Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 675 .Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd The test-all approach The test-all approach is best when you want to be certain that the the new version works on all tests developed for the previous version and any new tests. But what if you have limited resources to run tests and have to meet a deadline? What if running all tests as well as meeting the deadline is simply not possible? Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 676 .Copyright © 2013 Dorling Kindersley (India) Pvt.

We will discuss two of these known as test minimization and test prioritization. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Idea 2: Select a subset Tr of the original test set T such that successful execution of the modified code P’ against Tr implies that all the functionality carried over from the original code P to P‘is intact. Mathur 677 .Test selection Copyright © 2013 Dorling Kindersley (India) Pvt. Finding Tr can be done using several methods.

3. Regression test selection: The problem Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 678 .Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 9.

The task of identifying such obsolete tests is known as test revalidation. Ltd Regression Test Selection problem . Contents Foundations of Software Testing 2E Author: Aditya P. our goal is to determine Tr such that successful execution of P’ against Tr implies that modified or newly added code in P’ has not broken the code carried over from P. Note that some tests might become obsolete when P is modified to P’. Mathur 679 Copyright © 2013 Dorling Kindersley (India) Pvt. Such tests are not included in the regression subset Tr.Given test set T.

Regression Test Process Test selection Test setup Copyright © 2013 Dorling Kindersley (India) Pvt. Test sequencing Test execution Error correction Output analysis In this chapter we will learn how to select tests for regression testing. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Now that we know what the regression test selection problem is. let us look at an overall regression test process. Mathur 680 .

Ltd 9. Test selection using execution trace Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 681 .Copyright © 2013 Dorling Kindersley (India) Pvt.5.

find the execution trace of P for each test in T. Ltd Step 1: Given P and test set T. Mathur 682 . This step can be executed while constructing the CFGs of P and P’. Contents Foundations of Software Testing 2E Author: Aditya P.Overview of a test selection method Copyright © 2013 Dorling Kindersley (India) Pvt. Step 4: Traverse the CFGs and determine the a subset of T appropriate for regression testing of P’. Step 2: Extract test vectors from the execution traces for each node in the CFG of P Step 3: Construct syntax trees for each node in the CFGs of P and P’.

2. Ltd Let G=(N. and so on and that Start and End are two special nodes as discussed in Chapter 1. Suppose that nodes in N are numbered 1. E) denote the CFG of program P. N is a finite set of nodes and E a finite set of edges connecting the nodes. Mathur 683 . Contents Foundations of Software Testing 2E Author: Aditya P. Tno contains only tests valid for P’. It is obtained by discarding all tests that have become obsolete for some reason. Thus.Execution Trace [1] Copyright © 2013 Dorling Kindersley (India) Pvt. Let Tno be the set of all valid tests for P’.

Execution Trace [2] G traversed when P is executed against t. Ltd An execution trace of program P for some test t in Tno is the sequence of nodes in . As an example. Contents Foundations of Software Testing 2E Author: Aditya P. consider the following program. Mathur 684 Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd Here is a CFG for our example program. Mathur 685 . Contents Foundations of Software Testing 2E Author: Aditya P.Execution Trace [3] Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd Now consider the following set of three tests and the corresponding trace. Mathur 686 .Execution Trace [4] Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P.

For program P we obtain the following test vectors.Test vector Copyright © 2013 Dorling Kindersley (India) Pvt. denoted by test(n). Contents Foundations of Software Testing 2E Author: Aditya P. Ltd A test vector for node n. Mathur 687 . is the set of tests that traverse node n in the CFG.

Recall that Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 688 . Contents Foundations of Software Testing 2E Author: Aditya P. Here sample syntax trees for the example program.Syntax trees A syntax tree is constructed for each node of CFG(P) and CFG(P’). Ltd each node represents a basic block.

Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 689 . Ltd Given the execution traces and the CFGs for P and P’.Test selection [1] Copyright © 2013 Dorling Kindersley (India) Pvt. the following three steps are executed to obtain a subset T’ of T for regression testing of P’.

If two two nodes N in CFG(P) and N’ in CFG( P’) are found to be syntactically different. The descent proceeds in parallel and the corresponding nodes are compared. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd The basic idea underlying the SelectTests procedure is to traverse the two CFGs from their respective START nodes using a recursive descent procedure. all tests in test (N) are added to T’.Test selection [2] Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 690 .

Try the SelectTests algorithm and check if you get T’={t1. t3}. Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Suppose that function g1 in P is modified as follows. Mathur 691 .Test selection example Copyright © 2013 Dorling Kindersley (India) Pvt.

say. Mathur 692 . Ltd Issues with SelectTests Think: What tests will be selected when only.Copyright © 2013 Dorling Kindersley (India) Pvt. one declaration is modified? Can you think of a way to select only tests that correspond to variables in the modified declaration? Contents Foundations of Software Testing 2E Author: Aditya P.

6. Test selection using dynamic slicing Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 693 . Ltd 9.Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 694 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Dynamic slice . The dynamic slice of P with respect to t and v. Let trace(t) be the execution trace of P when executed against test t. is the set of statements in P that (a) lie in trace(t) and (b) effected the value of v at L. L). denoted as DS(t. Question: What is the dynamic slice of P with respect to v and t if L is not in trace(t)? Contents Foundations of Software Testing 2E Author: Aditya P.Let L be a location in program P and v a variable used at L. v.

Ltd The DDG is needed to obtain a dynamic slice. There are no edges among these nodes.Dynamic dependence graph (DDG) Copyright © 2013 Dorling Kindersley (India) Pvt.] Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 695 . Control and data dependence edges are added from n to the existing nodes in G. Here is how a DDG G is constructed. Step 3: For each successive statement in trace(t) a new node n is added to G. Step 2: Add to G the first node in trace(t). [Recall from Chapter 2 the definitions of control and data dependence edges. Step 1: Initialize G with a node for each declaration.

3. 3. 6. 8} Ignore declarations for simplicity. 4.Let t: <x=2. 5. Mathur 696 Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Construction of a DDG: Example [1] . 2. and for these values f1(x) is 0. Add a node to G corresponding to statement 1. y=4> Assume successive values of x to be 2. trace(t)={1. 6. 0 and 5. 1 Contents Foundations of Software Testing 2E Author: Aditya P. 2. 2. 2. and 3 respectively. 7. 7.

Mathur 697 Copyright © 2013 Dorling Kindersley (India) Pvt. Also add a data dependence edge from 2 to 1 as statement 2 is data dependent on statement 1. 7. Also add a data dependence edge from node 3 to node 1 as statement 3 is data dependent on statement 1 and a control edge from node 3 to 2. 1 should be… 3 if(f1(x)==0) 2 Add yet another node corresponding to statement 3 in trace(t). 2. 6. Ltd trace(t)={1. 4. 7. 3. 3. 8} .Construction of a DDG: Example [2] Add another node corresponding to statement 2 in trace(t). 6. 1 2 3 Contents Foundations of Software Testing 2E Author: Aditya P. 2. 2. 5.

3. should be… 3 if(f1(x)==0) Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 698 . 3. 7. 5. 2. 6.Construction of a DDG: Example [3] Copyright © 2013 Dorling Kindersley (India) Pvt. 6. Ltd trace(t)={1. 8} Continuing this way we obtain the following DDG for program P and trace(t). 7. 2. 4. 2.

Mathur 699 .Obtaining dynamic slice (DS) Copyright © 2013 Dorling Kindersley (India) Pvt. Step 3: Identify in G node n labeled L that contains the last assignment to v. If no such node exists then the dynamic slice is empty. Step 2: Construct the dynamic dependence graph G from P and trace(t). Ltd Step 1: Execute P against test t and obtain trace(t). v. v. n) of all nodes reachable from n. DS(t. other wise execute Step 4. n) is the dynamic slice of P with respect to v at location L and test t. including n. Step 4: Find in G the set DS(t. Contents Foundations of Software Testing 2E Author: Aditya P.

3. Ltd Suppose we want to compute the dynamic slice of P with respect to variable w at line 8 and test t shown earlier. This occurs at line 7 as marked. 8}. Traverse the DDG backwards from node 7 and collect all nodes reachable from 7. Mathur 700 . 5. Contents Foundations of Software Testing 2E Author: Aditya P. We already have the DDG of P for t. This gives us the following dynamic slice: {1. First identify the last definition of w in the DDG. 7. 2.Obtaining dynamic slice: Example Copyright © 2013 Dorling Kindersley (India) Pvt. 6.

Mathur 701 .Test selection using dynamic slice Copyright © 2013 Dorling Kindersley (India) Pvt. n2. If any of the modified nodes is in DS(t) then add t to T’. Which tests from T should be used to obtain a regression test T’ for P’? Find DS(t) for P.. Ltd Let T be the test set used to test P. P’ is the modified program. Contents Foundations of Software Testing 2E Author: Aditya P.nk be the nodes in the CFG of P modified to obtain P’. Let n1. .

Ltd In class exercise Suppose line 4 in the example program P shown earlier is modified to obtain P’. Mathur 702 . (a)  Should t be included in T’? (b)  Will t be included in T’ if we were to use the execution slice instead of the dynamic slice to make our decision? Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt.

Ltd You may have noticed that a DDG could be huge. the variable of interest. especially for large programs.Teasers [1] Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 703 . How can one reduce the size of the DDG and still obtain the correct DS? The DS contains all statements in trace(t) that had an effect on w. However there could be a statement s in trace(t) that did not have an effect but could affect w if changed. How can such statements be identified? [Hint: Read about potential dependence.] Contents Foundations of Software Testing 2E Author: Aditya P.

Ltd Suppose statement s in P is deleted to obtain P’? How would you find the tests that should be included in the regression test suite? Suppose statement s is added to P to obtain P’? How would you find the tests that should be included in the regression test suite? In our example we used variable w to compute the dynamic slice. how would you select the variable for which to obtain the dynamic slice? Contents Foundations of Software Testing 2E Author: Aditya P. While selecting regression tests. Mathur 704 .Teasers [2] Copyright © 2013 Dorling Kindersley (India) Pvt.

8 Test selection using test minimization Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd 9. Mathur 705 .

Contents Foundations of Software Testing 2E Author: Aditya P. suppose that P contains two functions. Mathur 706 .Copyright © 2013 Dorling Kindersley (India) Pvt. To illustrate test minimization. Ltd Test minimization [1] Test minimization is yet another method for selecting tests for regression testing. main and f. Now suppose that P is tested using test cases t1 and t2. During testing it was observed that t1 causes the execution of main but not of f and t2 does cause the execution of both main and f.

In this example we have used function coverage to minimize a test suite {t1. t2} to a obtain the regression test suite {t2}.Test minimization [2] Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. the regression test suite consists of only t2. Thus. Which of the two test cases should be included in the regression test suite? Obviously there is no need to execute P’ against t1 as it does not cause the execution of f. Mathur 707 . Ltd Now suppose that P’ is obtained from P by making some modification to f.

Contents Foundations of Software Testing 2E Author: Aditya P. def-use chains. Ltd Test minimization [3] Test minimization is based on the coverage of testable entities in P. and mutants. decisions. One uses the following procedure to minimize a test set based on a selected testable entity. Testable entities include.Copyright © 2013 Dorling Kindersley (India) Pvt. for example. program statements. Mathur 708 .

Contents Foundations of Software Testing 2E Author: Aditya P. In our previous example TE is function. Let e1. Mathur 709 .ek be the k testable entities of type TE present in P..A procedure for test minimization Copyright © 2013 Dorling Kindersley (India) Pvt. Step 3: Find a minimal subset T’of T such that each testable entity is covered by at least one test in T’. e2. Step 2: Execute P against all elements of test set T and for each test t in T determine which of the k testable entities is covered. Ltd Step 1: Identify the type of testable entity to be used for test minimization. .

Mathur 710 . 3 Step3: A minimal test set for regression testing is {t1. The basic Copyright © 2013 Dorling Kindersley (India) Pvt. t3}. 3 t1: main: 1.Test minimization: Example Step 1: Let the basic block be the testable entity of interest. Contents Foundations of Software Testing 2E Author: Aditya P. 3 t2: main: 1. Ltd blocks for a sample program are shown here for both main and function f1. 3. f1: 1. 2. f1: 1. f1: 1. Step 2: Suppose the coverage of the basic blocks when executed against three tests is as follows: t1: main: 1. 3. 3. 2.

Mathur 711 Copyright © 2013 Dorling Kindersley (India) Pvt. Is the minimal test set unique? Why or why not? Is test minimization NP hard? How is the traditional set cover problem in mathematics related to the test minimization problem? What criteria should be used to decide the kind of testable entity to be used for minimization? Contents Foundations of Software Testing 2E Author: Aditya P. Ltd Test minimization: Teasers .

9 Test selection using test prioritization Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 712 . Ltd 9.Copyright © 2013 Dorling Kindersley (India) Pvt.

Mathur 713 . When very high quality software is desired. tests that cover the maximum number of a selected testable entity could be given the highest priority.Test prioritization Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. There is a small chance that if P’ were executed against a discarded test case it would reveal an error in the modification made. Tests are prioritized based on some criteria. it might not be wise to discard test cases as in test minimization. the one with the next highest coverage m the next higher priority and so on. For example. In such cases one uses test prioritization. Ltd Note that test minimization will likely discard test cases.

ek be the k testable entities of type TE present in P. Step 3: Arrange the tests in T in the order of their respective coverage. Let e1. Step 2: Execute P against all elements of test set T and for each test t in T. Test with the maximum coverage gets the highest priority and so on. Ltd A procedure for test prioritization Step 1: Identify the type of testable entity to be used for test minimization.. Mathur 714 .Copyright © 2013 Dorling Kindersley (India) Pvt. In our previous example TE is function. Contents Foundations of Software Testing 2E Author: Aditya P. e2. For each t in T compute the number of distinct testable entities covered. .

Mathur 715 . Ltd Using test prioritization Once the tests are prioritized one has the option of using all tests for regression testing or a subset. Contents Foundations of Software Testing 2E Author: Aditya P. In any case test are discarded only after careful consideration that does not depend only on the coverage criteria used. The choice is guided by several factors such as the resources available for regression testing and the desired product quality.Copyright © 2013 Dorling Kindersley (India) Pvt.

10. Ltd 9. Tools Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 716 .

Contents Foundations of Software Testing 2E Author: Aditya P. Such tool are especially useful when all tests are to be rerun. xSuds from Telcordia Technologies can be used for C programs to minimize and prioritize tests. they do not use any of the algorithms described here for test selection.Tools for regression testing Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Methods for test selection described here require the use of an automated tool for all but trivial programs. Instead they rely on the tester for test selection. Many commercial tools for regression testing simply run the tests automatically. Mathur 717 .

Copyright © 2013 Dorling Kindersley (India) Pvt. Contents Foundations of Software Testing 2E Author: Aditya P. execution of all tests might not be feasible. Ltd Summary [1] Regression testing is an essential phase of software product development. Mathur 718 . In such situations one can make use of sophisticated technique for selecting a subset of all tests and hence reduce the time for regression testing. In a situation where test resources are limited and deadlines are to be met.

Mathur 719 .Summary [2] Copyright © 2013 Dorling Kindersley (India) Pvt. Select tests using dynamic slices [based on execution traces and dynamic slices]. Ltd Test selection for regression testing can be done using any of the following methods: Select only the modification traversing tests [based on CFGs]. Select tests using code coverage [based on the coverage of testable entities]. Contents Foundations of Software Testing 2E Author: Aditya P. Select tests using execution slices [based on execution traces].

Contents Foundations of Software Testing 2E Author: Aditya P.Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Summary [3] Select tests using a combination of code coverage and human judgment [based on amount of the coverage of testable entities]. Most commercially available tools are best in situations where test selection is done manually and do not use the techniques described in this chapter. Use of any of the techniques mentioned here requires access to sophisticated tools. Mathur 720 .

Copyright © 2013 Dorling Kindersley (India) Pvt. Ltd Chapter 10 Unit Testing [Under Construction] Contents Foundations of Software Testing 2E Author: Aditya P. Mathur 721 .

Copyright © 2013 Dorling Kindersley (India) Pvt. Mathur 722 . Ltd Chapter 11 Integration Testing [Under Construction] Contents Foundations of Software Testing 2E Author: Aditya P.