Beruflich Dokumente
Kultur Dokumente
vn
2
Introduction
Agenda
Unit Test - What and Who?
Unit Test - Why?
Unit Test - How? (method, technique)
Unit Test - Practice (3-5 labs) + Q&A
3 04e-BM/DT/HDCV/FSOFT v2.2
Objectives
4 04e-BM/DT/HDCV/FSOFT v2.2
Unit Test What?
5 04e-BM/DT/HDCV/FSOFT v2.2
Unit Test: Deliverables
6 04e-BM/DT/HDCV/FSOFT v2.2
Unit Test Who ?
Example
8 04e-BM/DT/HDCV/FSOFT v2.2
Cost of bugs
$14,000
Percentage of Bugs
85% % Defects
Introduced in
this phase
% Defects
found in
in this phase
$1000
$ Cost to
$25 $130 $250 repair defect
in this phase
Coding Unit Funct Field Post
Test Test Test Release
Source: Applied Software
Measurement,
Capers Jones, 1996
9 04e-BM/DT/HDCV/FSOFT v2.2
Unit Test When ?
After Coding: for each module (class or function)
Before Integration Test
10 04e-BM/DT/HDCV/FSOFT v2.2
Unit Test How ?
UT processes: Follow UT process defined in
FSOFT
11 04e-BM/DT/HDCV/FSOFT v2.2
Unit Test How ?
Methodologies:
Black-box testing
White-box testing
Black-box testing
Functional testing: ensure each unit acts right as
its design
Business testing: ensure the software program
acts right as user requirement
12 04e-BM/DT/HDCV/FSOFT v2.2
Black-box Testing
Advantages
Dont need to understand about logic of source code
particularly effective with the porting projects
Dont need detail design document to create unit test
specification
we havent much difficulty with complex logic module
Disadvantages
Cant determine coverage level
Often NOT achieve 100% coverage
14 04e-BM/DT/HDCV/FSOFT v2.2
White-box Testing
Advantages
Can determine coverage level
Can achieve 100% coverage
Disadvantages
Must understand about logic of source code to create unit
test specification
Must use detail design document to create unit test
specification
With complex logic module (many while loop, for, branch,
recursive ), if use white box testing, we often have
difficulty
Spend a lot of effort or white box test
16 04e-BM/DT/HDCV/FSOFT v2.2
Black box test
17 04e-BM/DT/HDCV/FSOFT v2.2
Example Specification
18 04e-BM/DT/HDCV/FSOFT v2.2
Black box test: Equivalence
partitioning
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
19 04e-BM/DT/HDCV/FSOFT v2.2
Example Test Cases
1 >= 0 a >= 0
2 <0 b Error
20 04e-BM/DT/HDCV/FSOFT v2.2
Black box test: Boundary value
analysis
It is similar to equivalence partitioning, is a
selection of test cases, test input that check
bounding values
21 04e-BM/DT/HDCV/FSOFT v2.2
Example Test Cases
1 <0 a >= 0
2 >= 0 b Error
Input
Partitions (1)
(2)
- 0
+
1 2 3 4
5
Boundaries and test cases 22 04e-BM/DT/HDCV/FSOFT v2.2
White box test : Node
Example:
buy(dress, bag) {
A if dress already in bag
A
B display already bought it
else B C
C if bag is full
D display bag is full D E
else
E
buy dress F
display buy successful
F end if
G end if G
}
23 23
04e-BM/DT/HDCV/FSOFT v2.2
White box test: Statement
coverage
Total Nodes = 7;
A
24 04e-BM/DT/HDCV/FSOFT v2.2
White box test: Decision (branch)
coverage
A What branch coverage is
achieved by ABG, ACDFG,
B C ACEFG?
D E
4 in total.
F
4 covered
G
D E
3 in total.
F
3 covered
G
27 04e-BM/DT/HDCV/FSOFT v2.2
White box test: Comparison
28 04e-BM/DT/HDCV/FSOFT v2.2
Unit Testing Tools
UT Tools for
references:
Java: JUnit, J2MEUnit
C/C++: cppUnit
Python: pyUnit
Perl: PerlUnit
Visual Basic: vbUnit
C# .NET: Nunit, csUnit
Refferences:
http://www.testingfaqs.org/t-unit.html
www.junit.org
http://www.codeproject.com/gen/design/autp5.asp
29 04e-BM/DT/HDCV/FSOFT v2.2
Quizzes
30 04e-BM/DT/HDCV/FSOFT v2.2