Unit-2 STM
Unit-2 STM
Unit – II
Anom, Bmin
Anom, Bmin+
Anom, Bmax
Anom, Bmax-
Amin, Bnom
Amin+, Bnom
Amax, Bnom
Amax-, Bnom
Anom, Bnom
It can be generalized that for n variables in a module, 4n + 1 test cases can be designed with boundary value
Checking method.
Ex:
2. Robustness Testing Method: In this method, we are going to add another values to the
Boundary Chec king Values, they are:
--A value just greater than the Maximum value (Max+)
--A value just less than Minimum value (Min-)
When test cases are designed considering above points in addition to BVC, it is called Robustness
testing.
Amax+, Bnom
Amin-, Bnom
Anom, Bmax+
Anom, Bmin-
It can be generalized that for n input variables in a module, 6n + 1 test cases can be designed with robustness testing
3.Worst Case Testing Method:
We can again extend the concept of BVC by assuming more than one variable on the boundary. It is
called Worst Case testing method:
two variables, A and B. We can add the following test cases to the list of 9 test cases designed in BVC as:
It can be generalized that for n input variables in a module, 5n test cases can be designed with worst-case testing
Example 1:
A program reads an integer number within the range [1,100] and determines whether the number is
a prime number or not. Design all test cases for this program using BVC, Robust testing and worst-
case testing methods:
n=1
no of test cases=4n+1
=4*1+1
=5
In equivalence-partitioning technique we need to test only one condition from each partition.
This is because we are assuming that all the conditions in one partition will be treated in the same
way by the software.
Ex:
If one condition in a partition works, we assume all of the conditions in that partition will work, and
so there is little point in testing any of these others.
Equivalence partitioning method for designing test cases has the following goals:
Completeness Without executing all the test cases, we strive to touch the completeness of testing domain.
Non-redundancy When the test cases are executed having inputs from the same class, then there is
redundancy in executing the test cases.
Time and resources are wasted in executing these redundant test cases, as they explore the same type of bug.
Thus, the goal of equivalence partitioning method is to reduce these redundant test cases.
To use equivalence partitioning, one needs to perform two steps:
1. Identify equivalence classes
2. Design test cases
Identification of Equivalent Classes:
Fig: Equivalence classes
Different equivalent classes are formed by grouping inputs for which the behaviour
pattern of themodule is similar.
The rationale for forming Equivalence classes like this is the assumption that if the
specifications requiress exactly the same behaviour for each element in a class of values.
Example 2:
A program determines the next date in the calendar. Its input is entered in the
form of <ddmmyyyy> with the following range:
1 ≤ mm ≤ 12
1 ≤ dd ≤ 31
1900 ≤ yyyy ≤ 2025
Its output would be the next date or an error message ‘invalid date.’ Design
test cases using equivalence class partitioning method.
State Table Based Testing:
Tables are useful tools for representing and documenting many types of information relating to test
case design.
These are beneficial for the applications which can be described using state transition diagrams
and state tables.
Finite State Machine (FSM):
An FSM is a behavioural model whose outcome depends upon both previous and current inputs.
FSM model can be prepared for software structure or software behaviour. And it can be used as a
tool for functional testing.
State transition diagrams or State Graph:
A system or its components may have a number of states depending on its input and time.
For example, a task in an operating system can have the following states:
1. New State: When a task is newly created.
2. Ready: When the task is waiting in the ready queue for its turn.
3. Running: When instructions of the task are being executed by CPU.
4. Waiting: When the task is waiting for an I/O event or reception of a signal.
5. Terminated: The task has finished execution
States are represented by nodes
when one state is changed to another, it is called a transition
Transitions are represented by links that join the nodes.
State graph consists of:
• State: a condition in which a system is waiting for events
• Event: Input that may cause a transition
• Transition: Change from one state to another as result of event
• Action: operation initiated by transition
State Table:
State graphs of larger systems may not be easy to understand. Therefore, state graphs are converted
into tabular form for convenience sake, which are known as state tables.
State table also specify inputs, transitions and outputs.
The following conventions are used for state table:
--Each row of the table corresponds to a state.
--Each column corresponds to an input condition
--The box at the intersection of a row and a column specifies the next state (transition) and the
output.
The highlighted cells of the table are valid inputs causing a change of state.
Other cells are invalid inputs
• Test cases are produced in a tabular form known as the test case table which contains six columns
• Test case ID : a unique identifi er for each test case
• Test Source : a trace back to the corresponding cell in the state table
• Current State : the initial condition to run the test
• Event : the input triggered by the user
• Output : the current value returned
• Next State : the new state achieved
State Table Based Testing:
The procedure for converting state graphs and state tables into test cases is:
• 1. Identify the states
• 2. Prepare state transition diagram after understanding transitions between states
• 3. Convert the state graph into the state table
• 4. Analyse the state table for its completeness
• 5. Create the corresponding test cases from the state table
.
Let’s consider an ATM system function where if the user enters the invalid password
three times the account will be locked
Decision Table Based Testing:
Boundary Value Analysis and Equivalence class partitioning methods do not consider
combinationsof input conditions.
These methods consider the inputs separately.
Decision Table is another useful method to represent the information in a tabular method. It has the
speciality to consider complex combinations of input conditions and resulting actions.
Each operand or variable in a logical expression takes on the value, TRUE or FALSE.
Formation of Decision Table:
Example 2:
Example 3:
EXPANDING THE IMMATERIAL CASES IN DECISION TABLE :
• Immaterial cases (I) have been shown in the decision table which are don’tcare conditions.
• These conditions mean that the value of a particular condition in the specific rule does not make a difference
whether it is TRUE or FALSE.
• However, we should always test both the values of a don’t-care condition.
• So the rules in the table can be expanded
• Sometimes expanding the decision table to spell out don’t-care conditions can reveal hidden problems.
Cause Effect Graphing Based Testing:
Cause and effect graph is a dynamic test case writing technique.
Here causes are the input conditions and effects are the results of those input conditions.
Cause-Effect Graphing is a technique which starts with set of requirements and determines
the minimum possible test cases formaximum test coverage .
The goal is to reduce the total number of test cases still achieving the desired application
quality.
Disadvantage: It takes time to model all your requirements into this cause-effect
graph beforewriting test cases.
Identification of causes and effects: A cause is a distinct input condition identified in the problem.
Converison into decision table: The cause-effect graph obtained is converted into a limited entry
decision table by verifying state conditions in the graph.
Deriving test cases: The columns in the decision table are converted into tst cases.
Example:
• Design test cases for the following problem-
• If the character of the first column is ‘A’ or ‘B’ and the second column is a number, then the
file is considered updated. If the first character is erroneous, then message x should be printed.
If the second column is not a number, then message y should be printed.
•
• Step-01:
•
• Identify and describe the input conditions (causes) and actions (effect).
• The causes represented by letter “C” are as follows-
• C1 : The character in column 1 is ‘A’
• C2 : The character in column 1 is ‘B’
• C3 : The character in column 2 is a number
•
• The effects represented by letter “e” are as follows-
• e1 : File update (C1 OR C2) AND C3
• e2 : Message X is printed (NOT C1 AND NOT C2)
• e3 : Message Y is printed (NOT C3)
• Step-02:
• Step-03:
•
• Convert cause-effect graph into a decision table-
EXAMPLE 2:
Error Guessing:
Error Guessing is the preferred method when all the other methods fail.
It is a very practical case wherein the tester uses his intuition and makes a guess about
where the bug can be.
The tester does not have to use any particular testing technique.
The basic idea is to make a list of possible errors inerror prone situations and then develop
the test cases.
Thus there is no general procedure for this technique as it is largely an intuitive and ad-hoc
process.
For example:
Suppose you are testing a login page for a application and you are asked to identify any possible errors that may
occur during the login process. By error guessing technique, you might consider the following scenarios Entering
an invalid username and password combination
Entering a valid username but an incorrect password
Attempting to login with a username or password that exceeds the maximum character limit
Attempting to login with a username or password that does not meet the required complexity criteria
Entering a valid username and password but with the caps lock key on
Attempting to login without entering any credentials
Attempting to login with special characters in the username or password field
--By considering these scenarios, you can identify potential errors
Statement Coverage:
It is assumed that if all the statements of the module are executed once, every bug will be
notified. If we want to cover every statement in the above code, then the following test cases must be
designed:
Test case 1: x = y = n, where n is any number
Test case 2: x = n, y = n’, where n and n’ are different numbers.Test
case 3: x>y
Test case 4: x<y
These test cases will cover every statement in the code segment, however
statement coverage is a poor criteria for logic coverage. We can see that test
case 3 and 4 are sufficient to execute all the statements in the code. But, if
we execute only test case 3 and 4, then conditions and paths in test case 1
will never be tested and errors will go undetected. Thus, statement coverage is a
necessary but not a sufficient criteria for logic coverage
Decision or Branch Coverage:
Branch Coverage states that each decision takes on all possible outcomes. In other words each
branch direction must be traversed atleast once. The different test cases that can be designed are:
Test case 1: x = y Test case 3: x < y
Test case 2: x != y Test case 4: x > y
Condition Coverage:
It states that each condition in a decision takes on all possible outcomes at least once. For
example consider the following statement: while((I<5) && (J<COUNT))
The different test cases are:
Test case 1: I <= 5, J < COUNTTest
case 2: I > 5, J > COUNT
Segment: Path consists of segments. The smallest segment is a link, that is, a single process thatlies
between two nodes.
Path Segment: A path segment is a succession of consecutive links that belongs to some path.
Length of a Path: The length of a path is measured by the number of links in it and not by the
number of instructions or statements executed along the path.
Independent Path: An independent path is any path through the graph that introduces at least one new
set of processing statements or new conditions.
Cyclomatic Complexity:
--It provides a quantitative measure of the logical complexity of a program
--Defines the number of independent paths in the basis set
--Provides an upper bound for the number of tests that must be conducted to ensure all statements
have been executed at least once
--Can be computed three ways
-->The number of regions
-->V(G) = E – N + 2, E is the number of edges and N is the number of nodes in graph G
-->V(G) = P + 1, where P is the number of predicate nodes in the flow graph G
Graph Matrices:
Flow graph is an effective aid in path testing. However, path tracing with the use of flow
graphs may be a cubersome and time consuming activity.
Graph Matrix ,a data structure is thesolution which can assist in developing a tool for automation of
path tracing.
Graph Matrix:
A Graph Matrix is a square matrix whose size is equal to the number of nodes on the flow
graph. Each row and column corresponds to an identified node, and matrix entries correspond to
connections between nodes.
The following points describe a graph matrix:
--Each cell in the matrix can be a direct connection or link between one node to another node.
--If there is a connection from node ‘a’ to node ‘b’, then it does not mean that there is connection
from node ‘b’ to node ‘a’.
--Conventionally, to represent a graph matrix, digits are used for nodes and letter symbols for edges or
connections
Connection Matrix:
If we add link weights to each cell entry, then graph matrix can be used as a powerful tool in testing.
The links between two nodes are assigned a link weight which becomes the entry in the cellof matrix.
The link weight provides information about control flow. when the connection exists, then the link
weight is 1, otherwise 0.
A matrix defined with link weights is called a connection matrix.
USE OF CONNECTION MATRIX IN FINDING CYCLOMATIC
COMPLEXITY NUMBER
Connection matrix is used to see the control flow of the program. Further, it
is used to find the cyclomatic complexity number of the flow graph. Given
below is the procedure to find the cyclomatic number from the connection
matrix:
Step 1: For each row, count the number of 1s and write it in front of that
row.
Step 2: Subtract 1 from that count. Ignore the blank rows, if any.
Step 3: Add the final count of each row.
Step 4: Add 1 to the sum calculated in Step 3.
Step 5: The final sum in Step 4 is the cyclomatic number of the graph.
Loop Testing:
Simple loops:
The following test cases should be considered for simple loops while testing them:
--> Check whether the loop control variable is negative.
--> Write one test case that executes the statements inside the loop.
--> Write test cases for a typical number of iterations through the loop.
--> Write test cases for checking the boundary values of maximum and minimum number of iterations
defined (say min and max) in the loop. It means we should test for the min, min+1, min-1,max-1, max
and max+1 number of iterations through the loop.
Nested loops
• When two or more loops are embedded, it is called a nested loop,
Example
• while(condition 1) {
• while(condition 2) {
• statement(s);
}
}
• Example
• while(condition 1) {
• statement(s);
• }
• while(condition 2) {
• statement(s);
• }
Unstructured loops
• The combination of nested and concatenated loops is known as an unstructured loop.
• Example
while(){
for()
{}
while()
{}
}
In addition to the above two character data anomalies, there may be a single character data
anomalies. To represent these types of anomalies, we take the following conventions:
~x: indicates all prior actions are not of interest to x.x~:
indicates all post actions are not of interest to x.
Static Flow Testing: With static analysis, the source code is analysed without executing it. Let us
consider an example of an application given below:
Example:
main()
{
int a=10,b=10,c; c=a+b;
printf(“Value=%d”,c);
}
For Variable 'a':
Pattern Line Number Explanation
-d 3 Normal Case: Allowed
du 3-4 Normal Case: Allowed
uk 4 Normal Case: Allowed
Mutation Testing
Mutation testing is the process of mutating some segment of code(putting some error in the code) and
then testing this mutated code with some test data.
If the test data is able to detect the mutationsin the code. Mutation testing helps a user create test data
by interacting with the user to iteratively strengthen the quality of test data.
During mutation testing, faults are introduced into a program by creating many versions of the
program, each of which contains one fault.
Test data are used to execute these faulty programs with the goal of causing each faulty program to fail.
Faulty programs are called mutants of the original program and a mutant is said to be killed when atest
case causes it to fail. When this happens, the mutant is considered dead
Primary Mutants:
When the mutants are single they are called as primary Mutants. Mutation operators are
dependent on programming languages.
Example: if(a>b)
x = x+y;else
x=x-y;
printf(“%d”,x);
Secondary Mutants:
This class of mutants is called secondary mutants when multiple levels of
mutation are applied on the initial program. In this case, it is very difficult to
identify the initial program from its mutants.
Example: if(a<b)
c=a;M1:
if(a<=b-1)
c=a;
M3: if(a==b)
c=a+1;
MUTATION TESTING PROCESS
The mutation testing process is