Lesson 3.1 - Unit Testing Basics
Lesson 3.1 - Unit Testing Basics
Code: N/A
Authors: HaiPT1
Course: <Course-Name>
Conductor: <Acc> –
<Unit>
Agenda(90 minutes)
Unit Test - What and Who?
Unit Test - Why?
Unit Test - How? (method, technique)
Unit Test - Practice (3-5 labs) + Answer
$14,000
85% % Defects
Percentage of Bugs
Introduced in
this phase
% Defects
found in
in this phase
$1000
$ Cost to
After Coding
Before Integration Test
UT processes
Follow the UT process defined in FSOFT UT Guidelines
Black-box testing
Functional testing: ensure each unit acts right as its design
Business testing: ensure the software program acts right as
user requirement
White-box testing
Developer does himself
• Check syntax of code by compiler to avoid syntax errors
• Run code in debug mode, line by line, through all independent paths of
program to ensure that all statement of codes has been executed at least
one time
• Examine local data structure to ensure that data stored temporarily
maintains its integrity during all all steps of code execution
• Check boundary conditions to ensure that code will run properly at the
boundaries established as requirements
• Review all error handling paths
Apply WB Test techniques
• See next slides
Test Case 2: Input -10, Return 0, Output "Square root error - illegal negative
input“
• Use the second and third statements in the specification
• ("When given an input of less than 0, the error message "Square root
error - illegal negative input" shall be displayed and a value of 0
returned.”).
Divide the input of a program into classes of data from which test
cases can be derived. This might help you to reduce number of test
cases that must be developed.
Behavior of software is equivalent for any value within particular
partition
A limited number of representative test cases should be chosen from
each partition
Invalid inputs
Outputs
System
Valid inputs
1 >= 0 a >= 0
2 <0 b Error
Test Case 2: Input -10, Return 0, Output "Square root error - illegal negative input“
• Use the < 0 input partition (2)
• Use the “Error” output partition (b)
1 >= 0 a >= 0
2 <0 b Error
Input
Partitions (1) (2)
- 0 +
1 2 3 4 5
Boundaries and test cases
E
buy dress F
display “buy successful”
F end if
G end if G
}
D E
4 in total.
F
4 covered
G
D E
3 in total.
F
3 covered
G