Week 10
Week 10
Week 10
Rajib Mall
CSE Department
IIT KHARAGPUR
1
Design of Test Cases
• Systematic approaches are required to design an
effective test suite:
–Each test case in the suite should target different
faults.
2
Testing Strategy
• Test Strategy primarily addresses:
– Which types of tests to deploy?
3
Quiz: How would you use this information
40% for planning test effort?
# of Bugs
Considering
Detected 25% Past Bug
Detection
Data…
15%
10%
10%
4
Quiz: How would you use
this for planning unit test
effort?
Problems 50% Consider Past
Detected
Bug Detection
30%
Data…
10% 10%
5
Quiz: How would you use
Distribution of
this for planning Release 2 testing?
Error Prone
Number of Modules
bugs customer
Detected
reported bugs
for Release 1
M1 M2 M3 M4 M5 M6
7
When and Why of Unit Testing?
• Unit testing carried out:
• After coding of a unit is complete and it compiles
successfully.
• Simulates the behavior of a function that calls and supplies necessary data
to the function being tested.
– Stub
• Simulates the behavior of a function that has not yet been written.
10
Unit Testing
PROCEDURE
STUB UNDER TEST DRIVER
CALL
11
Quiz
• Unit testing can be considered as which one of the
following types of activities?
– Verification
– Validation
12
Design of Unit Test Cases
• There are essentially three main approaches to
design test cases:
–Black-box approach
–Grey-box approach
13
Black-Box Testing
• Test cases are designed using only functional
specification of the software:
Input Software Output
–Without any knowledge of the
internal structure of the software.
14
What is Hard about BB Testing
• Data domain is large
15
What’s So Hard About Testing?
• Consider int check-equal(int x, int y)
• Assuming a 64 bit computer
–Input space = 2128
16
Solution
• Construct model of the data domain:
17
White-box Testing
• To design test cases:
–Knowledge of internal structure of software
necessary.
18
• Software considered as a black box: Black Box
–Test data derived from the specification Testing
• No knowledge of code necessary
19
• Scenario coverage Black-Box Testing
• Equivalence class partitioning
• Boundary value testing
• Cause-effect (Decision Table) testing
• Combinatorial testing
• Orthogonal array testing
20
Start use case Use Case
Scenarios
Alternative flow 3 Alternative flow 1
Alternative flow 2
Alternative flow 4
end use case
end use case
end use case
Deriving test cases from use cases
1. Identify the use case scenarios
2. For each scenario, identify one or more test cases
3. For each test case, identify the conditions that will
cause it to execute.
4. Complete the test case by adding data values
22
Scenario Originating Alternative Next Next
number flow flow alternative alternative Identify
1 Basic flow
use case
scenarios:
2 Basic flow Alt. flow 1
Example
3 Basic flow Alt. flow 1 Alt. flow 2
23
• Parameters of any test case:
Identify the
– Conditions
test cases
– Input (data values)
– Expected result
– Actual result
Test Scenario/ Data Data Data Exp. Actual
case ID conditon value 1 value 2 value N results results
1 Scenario 1
2 Scenario 2
3 Scenario 3
24
Equivalence Class
Testing
03/08/10 25
Equivalence Class Partitioning Start use case
27
Equivalence Class Partitioning
• How do you identify equivalence classes?
–Identify scenarios
–Examine the input data.
–Examine output
• Few guidelines for determining the equivalence classes
can be given…
28
•If an input is a range, one valid and two invalid equivalence classes are defined.
Example: 1 to 100 1 100
•If an input is a set, one valid and one invalid equivalence classes are defined. Example:
{a,b,c}
•If an input is a Boolean value, one valid and one invalid class are defined.
Example: Guidelines
to Identify
•Area code: input value defined between 10000 and 90000--- range
Equivalence
•Password: string of six characters --- set Classes
29
Equivalent class partition: Example
• Given three sides, determine the type of the triangle:
– Isosceles
– Scalene
– Equilateral, etc.
30
Equivalence Partitioning
• First-level partitioning:
– Valid vs. Invalid test cases
Valid Invalid
31
Equivalence Partitioning
Invalid
Valid
32
Equivalence Partitioning
• Create a test case using at least
one value from each
equivalence class
Invalid
Valid
33
Equivalence Class Partitioning
• If the input data to the program is specified by a range
of values:
–e.g. numbers between 1 to 5000.
34
Equivalence Class Partitioning
• If input is an enumerated set of values, e.g. :
–{a,b,c}
• Define:
–One equivalence class for valid input values.
–Another equivalence class for invalid input values..
35
Example
SQRT
36
Example (cont.)
• Three equivalence classes:
–The set of negative integers,
–Set of integers in the range of 1 and 5000,
–Integers larger than 5000.
1 5000
37
Example (cont.)
• The test suite must include:
–Representatives from each of the three equivalence
classes:
38
Equivalence Partitioning
• A set of input values constitute an equivalence class if the tester
believes that these are processed identically:
– Example : issue book(book id);
39
Equivalence Partitioning: Example 1 File Type
URL
40
Equivalence Partitioning: Single Parameter Function
• issue-book(int book-id)
41
Multiparameter Functions
• postGrade(Roll,CourseNo, Grade)
Invalid Invalid
Valid Invalid
Valid Valid
42
Multiparameter
int Normalization Factor; Function Accessing
postGrade(Roll,CourseNo, Grade) Global Variables
{ Grade=Grade*NormalizationFactor
-------}
43
Multi Parameter Equivalence Partitioning: Example
Input Parameter Valid Equivalence Classes Invalid Equivalence
Classes
? ?
An integer N such that:
-99 <= N <= 99
? ?
Phone Number
Area code: [11,…, 999]
Suffix: Any 6 digits
44
Equivalence Partitioning: Example
Input Valid Equivalence Classes Invalid Equivalence Classes
45
age predict-employability(age, education)
>30
Weak
Equivalence
Class Testing
20-30
46
predict-employability(age, education)
age
>30 Strong
Equivalence
Class Testing
20-30
20-30
School UG PG
yrs of education
48
• Design Equivalence class test cases: compute-interest(days)
• A bank pays different rates of interest on a deposit depending on
the deposit period.
Quiz 1
– 3% for deposit up to 15 days
– 4% for deposit over 15days and up to 180 days
– 6% for deposit over 180 days upto 1 year
– 7% for deposit over 1 year but less than 3 years
– 8% for deposit 3 years and above
49
• Design Equivalence class test cases: compute-interest(principal, days)
• For deposits of less than or equal to Rs. 1 Lakh, rate of interest:
– 6% for deposit upto 1 year
– 7% for deposit over 1 year but less than 3 years
Quiz 2
– 8% for deposit 3 years and above
• For deposits of more than Rs. 1 Lakh, rate of interest:
– 7% for deposit upto 1 year
– 8% for deposit over 1 year but less than 3 years
– 9% for deposit 3 years and above
50
• Design equivalence class test cases. Quiz 3
– substr(s1,s2);
51
Special Value
Testing
03/08/10 52
52
Special Value Testing
• What are special values?
– The tester has reasons to believe that execution with certain
values may expose bugs:
53
• Some typical programming errors occur:
Boundary
–At boundaries of equivalence classes
Value Analysis
–Might be purely due to psychological factors.
1 100
• Programmers often commit mistakes in the:
–Special processing at the boundaries of equivalence
classes.
54
Boundary Value Analysis
• Programmers may improperly use < instead of
<=
• Boundary value analysis: 1 100
56
Boundary Value Testing Example
• Process employment applications based on a person's age.
0-16 Do not hire
16-18 May hire on part time basis
18-55 May hire full time
55-99 Do not hire
58
• Corrected boundaries: Boundary Value Testing Example (cont)
0–15 Don't hire
16–17 Can hire on a part-time basis only
18–54 Can hire as full-time employees
55–99 Don't hire
59
Boundary Value Testing Example (cont)
• The code to implement the corrected rules is:
If (applicantAge >= 0 && applicantAge <=15) hireStatus="NO";
If (applicantAge >= 16 && applicantAge <=17) hireStatus="PART";
If (applicantAge >= 18 && applicantAge <=54) hireStatus="FULL";
If (applicantAge >= 55 && applicantAge <=99) hireStatus="NO";
• Special values on or near the boundaries in this example are {-1, 0, 1}, {14, 15,
16}, {17, 18, 19}, {54, 55, 56}, and {98, 99, 100}.
60
Boundary Value Analysis
• Create test cases to test boundaries of equivalence classes
61
Example 1
• For a function that computes the square root of an
integer in the range of 1 and 5000:
–Test cases must include the values:
{0,1,2,4999,5000,5001}.
1 5000
62
• Consider a program that reads the “age” of employees and
computes the average age.
Example 2
input (ages) → Program → output: average age
Assume valid age is 1 to 150
1 150
• How would you test this?
– How many test cases would you generate?
– What type of test data would you input to test this program?
63
Boundaries of the inputs
The “basic” boundary value testing
would include 5 test cases:
predict-longevity(age)
1. - at minimum boundary
2. - immediately above minimum
1 <= age <= 150
3. - between minimum and
1 age 150
maximum (nominal)
4. - immediately below maximum
5. - at maximum boundary
64
• How many test cases for the example ? Test Cases for the
Example
– answer : 5
65
Multiple Parameters: Independent distinct Data
• Suppose there are 2 “distinct” inputs that are assumed to be independent
of each other.
– Input field 1: years of education ( say 1 to 23 )
– Input field 2: age (1 to 150)
66
age
2–
Independent
inputs
yrs of ed.
- Note that there needs to be only 9 test cases for 2 independent inputs.
- In general, need (4z + 1) test cases for z independent inputs.
67
Boundary Value Test
Given f(x,y) with constraints a ≤ x ≤ b
Boundary Value analysis focuses on the c ≤ y ≤ d
boundary of the input space to identify
test cases. y
68
Weak Testing: Single Fault Assumption
• Premise: “Failures rarely occur as the result of the
simultaneous occurrence of two (or more) faults”
• Under this:
– Hold the values of all but one variable at their nominal
values, and let that one variable assume its extreme
values.
69
Boundary Value Analysis: Robustness
• Numeric values are often entered as strings :
70
Robustness testing
• This is just an extension of the Boundary Values to include invalid
values:
X
71
2 – independent inputs for robustness test
X
72
Some Limitations of Boundary Value Testing
• How to handle a set of values?
• How about set of Boolean variables?
– True
– False
• May be radio buttons
• What about a non-numerical variable whose values are
text?
73
Quiz: BB Test Design
• Design black box test suite for a function that
solves a quadratic equation of the form
ax2+bx+c=0.
Complex
• Equivalence classes Coincident
Real
– Invalid Equation Unique