Unit Testing Guidelines Software Unit Testing
Unit Testing Guidelines Software Unit Testing
Unit Testing Guidelines Software Unit Testing
12/03/2002
Table of Contents
1. INTRODUCTION............................................................................................4
1.1. Unit Testing Approach................................................................................4
1.2. Audience...................................................................................................4
1.3. Contributors...............................................................................................4
2. Purpose and Scope of Document..........................................................5
2.1. Purpose.....................................................................................................5
2.2. Scope........................................................................................................5
3. Explanation of Unit Testing.....................................................................6
3.1. What is it....................................................................................................6
3.2. Who does it...............................................................................................6
3.3. Why do it...................................................................................................6
4. Unit Testing Techniques..........................................................................7
4.1. Assume you will find errors........................................................................7
4.2. Own Checklist of Common Errors.............................................................7
4.3. Use Data most likely to cause errors.........................................................7
4.4. Use Data that make Hand-Checks easier..................................................7
4.5. Make sure all paths in code is covered......................................................7
4.6. Creation of Test Stubs/Harness and Automated Unit Tests........................7
4.7. Test as you go...........................................................................................8
4.8. Plan your tests...........................................................................................8
4.9. Record you Results...................................................................................8
4.10. Type of things to test for............................................................................8
5. Unit Test Templates..................................................................................9
5.1. Personal Development Checklist of Common Errors.................................9
5.2. Unit Test Plan............................................................................................9
6. References...............................................................................................12
1.Introduction
This document describes the approach to unit testing that is to be used to verify that
each particular piece of code that has been written performs the function that it is
designed to do.
1.2. Audience
The audience for this document are software developers and quality
managers
1.3. Contributors
Document Author Scott Highet
2.2. Scope
This document details on templates and techniques that are to be used
by Software Developers.
It does not cover the XP Unit Testing Techniques. This will be covered
in a separate document.
Include these tests in any unit test you create where applicable
4.9.1 Functional
Does the piece of code functionally perform the task it is
designed to do?
4.9.2 Boundaries
What are the minimum, maximum values for the function, will
the function accept strange characters, reserved SQL
characters, alpha and numeric values? What happens if they
are not within these boundaries?
4.9.3 Termination
What happens in the normal termination of the function? What
about an abnormal termination of the function? Will the
application continue or will an error occur. Is the error trapped?
4.9.4 Outputs
What are the expected outputs of the function? Where do they
go, what else uses them, what happens if the output is nothing?
What happens if the output cannot be passed to the next
function? i.e. The database was unavailable when attempting to
write to it
4.9.5 Algorithms and Computations
Do all the algorithms and computations work, what happens if
the wrong values are passed to them, are the variables stored
as correct types i.e. will the result exceed 32267 (integer)
4.9.6 Inputs
What are the expected inputs to the function? Where do they
come from? What happens if they do not get passed in? What
happens if they are the wrong type? i.e. an alpha instead of a
numeric. Do they rely on any third party application?
4.9.7 Interaction
What other modules/functions does this interact with? Will
those be effected by the change?
4.9.8 Transactions
What type of transactions will occur? What will happen if a
single transaction fails, is interrupted or succeeds? Are the
transactions event driven, system initiated, user driven, or time
driven?
If Problem has
been mastered
Description Steps to
of Problem prevent it
Resulting Defects
if not prevented
The actions can be determined by using the Unit Test Techniques detailed
earlier in this document.
The Unit Test Plan can be as brief or verbose as the Developer or the
Project Manager thinks is necessary for the project, as long as the Test
Plan describes and tests to the appropriate level.
This is an example of a Unit Test Plan. The template can be found at put
template here
Reference to Design,
Client Name Change Request or
Defect
Details of Developer /
Description Project / Module and
of Test Function
Inputs Required
(if any)