Unit Testing
START
Internal Use
Learning Goals
After the course, attendees will be able to:
Be introduced test levels
Be introduced the lowest test level Unit Test
Internal Use 1/12
Table of contents
Test Levels
Unit Test Level
Quiz
Internal Use 1/12
Test Levels – What?
➢A group of test activities that are organized
and managed together.
➢Each test level is specifically service for a
development stage -> V-model
Internal Use
V-Model
Internal Use
Test Levels
➢Unit testing (Component testing)
➢Integration testing (Combination testing)
➢System testing
➢Acceptance testing
Internal Use
Test Levels
Test levels are characterized by the following
attributes:
➢Specific objectives
➢Test basis, referenced to derive test cases
➢Test object (i.e., what is being tested)
➢Typical defects and failures
➢Specific approaches and responsibilities
Internal Use
Unit Test – What?
➢ Verify that individual UNITs of software program are
working properly follow detailed design
➢ A UNIT(component) is the smallest testable part of
an application, it can be:
✓Program statements
✓Class, Function, Procedure
✓Module
✓Individual program
Internal Use
Unit Test – Objectives
✓ Reducing risk
✓ Verifying whether the functional and non-
functional behaviors of the component are as
designed
and specified
✓ Building confidence in the component’s quality
✓ Finding defects in the component
✓ Preventing defects from escaping to higher test
levels
Internal Use
Unit Test – Why?
$14,000
➢ Faster Debugging
85% % Defects
➢ Better Design Introduced in
Percentage of Bugs
this phase
➢ Reduce Future % Defects
Cost (Quality found in
in this phase
$1000
Effort & $ Cost to
Correction Cost) $25 $130 $250 repair defect
in this phase
Coding Unit Funct Field Post
Test Test Test Release
Internal Use
Unit Test – Inputs (Test Basis)
✓ Detailed design
✓ Code
✓ Data model
✓ Component specifications
Internal Use
Unit Test – Types/Technique
➢Statement Testing: execute all statements at
least once
➢Decision/Branch Testing: execute each
decision/branch at least once
➢Path Testing: execute all paths in the
program at least once
Internal Use
Unit Test – Implementation
➢Doer: developer/coder, who develop the code
➢How: using one or more unit testing types in
following orders:
✓ Top-Down Unit Testing: stubs are required
✓ Bottom-up Unit Testing: drivers are required
Stubs and drivers are usually used in Unit Testing to
replace missing components, software
Internal Use
Top-Down Unit Testing
➢Stubs: called by software component
Stub
Stub
B
Stub
Internal Use
Bottom-up Unit Testing
➢Driver: call software component
Test Test
Drivers Drivers
Level N Level N
Test
Drivers
Level N-1
Internal Use
Unit Test – Typical defects and failures
➢Incorrect functionality (e.g., not as described
in design specifications)
➢Data flow problems
➢Incorrect code and logic
Internal Use
Unit Test – Tools
UT Tools for references:
Java: Junit (www.junit.org)
C/C++: cppUnit
(http://sourceforge.net/projects/cppunit/)
Python: pyUnit (http://pyunit.sourceforge.net/)
Perl: PerlUnit (http://perlunit.sourceforge.net/)
Visual Basic: vbUnit (http://www.vbunit.com/)
C#: csUnit (http://www.csunit.org/)
.NET: Nunit (http://www.nunit.org/)
Internal Use
Quiz!
There are 5 questions below.
Click NEXT button to start!
Internal Use
Quiz! Question 1 of 5 01: 08
What is a test level?
A group of test activities that are organized together
One or more test design specification documents
A test type
An ISTQB certification
Submit
Internal Use
Quiz! Question 2 of 5 01: 08
What is the normal order of activities in which software testing is
organized?
Unit, integration, system, acceptance
System, integration, unit , acceptance
Unit, integration, acceptance, system
None of the above
Submit
Internal Use
Quiz! Question 3 of 5 01: 08
Why is unit testing?
Faster Debugging
Reduce Future Cost
Both of the above
None of the above
Submit
Internal Use
Quiz! Question 4 of 5 01: 08
To test a function, the programmer has to write a _________,
which calls the function to be tested and passes it test data
Stub
Driver
Proxy
None of the above
Submit
Internal Use
Quiz! Question 5 of 5 01: 08
Drivers are also known as
i. Spade
ii. Test harness
iii. Scaffolding
i , ii are true and iii is false
i , iii are true and ii is false
ii , iii are true and i is false
All of the above are true
Submit
Internal Use
Exit Course
THANK YOU
You have completed “Unit Testing" Lecture.
Click EXIT button to exit course and discover
the next Lecture “Integration Testing".
EXIT
Internal Use