Definition and Overview b y P aul M Watt code of the damned com Definition Unit Test Verifies a single minimal unit of source code The purpose of unit testing is to isolate the smallest testable parts of an API and verify that they function in isolation ID: 592165
Download Presentation The PPT/PDF document "Unit Tests" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Unit Tests
Definition and Overview
b
y
P
aul M. Watt @ code of the damned . comSlide2
Definition
Unit Test:
Verifies a single minimal unit of source code. The purpose of unit testing is to isolate the smallest testable parts of an API and verify that they function in isolation.**
**API Design for C++, Martin Reddy; p. 295Slide3
Test Harness
A
collection of tests for the System Under Test (SUT)*. Behaves
as a
software vise
that keeps the code fixed in place while you make changes.
System Under Test
(SUT)
Test Harness
System Under Test (SUT)*: Industry standard term to indicate the targeted test component, class, function, module etc.Slide4
Unit Tests Are an Asset
Project Value Lost when Unit Tests are Lost
Value increases with Maintained Tests
Productivity Increased by finding defects closer to the moment they were introduced.Slide5
What to Do
Use
a unit test frameworkIsolate your code (SUT) to develop, compile
and run in an independent test
harness*
The developer writes
the tests as they develop the SUTVerify a single path of code with each test*
Isolate each test from one another*
Ensure that your tests execute quickly (preferably < 1sec for each test harness)
Test Early / Test
Often*
All of the system’s unit tests must pass before you deliver your source code
Maintain the unit tests along with the source code*Items marked with an asterisk (*) indicate tasks that most unit test frameworks simplify Slide6
What to Avoid
Do not delete tests
Do not comment out testsDo not write the tests outside of the prescribed test framework
Your tests must
run without specialized
hardware
Your tests must not require manual interactionDo not print directly to the console;
Use
the test frameworks output APIs and only for
errors
Avoid the use of expensive resourcesSlide7
Qualities and Benefits
The software becomes more correct, reliable, and robust
Instills confidence in the developer of the softwareProvides a rapid feedback
loop
Poor changes are immediately detected and the isolation of the recent changes makes them simpler to correct
Instills confidence
and trust by management and other teams
Creates a consistently repeatable process of verification
This verification process can
be automated
P
roject risk is reduced
Development schedules become more determinant Overall length of the Software Development Life Cycle is decreased Less time is spent in integration and acceptance testing.Slide8
Resources
Code of the Damned
The Purpose of a Unit TestUnit Test Frameworks
Test Driven Development
Books
xUnit
Test Patterns: Refactoring Test Code
by Gerard
Meszaros
Working Effectively with Legacy Code
by Michael C. Feathers, Author of CppUnit(Lite)
Test Driven Development: By Example
by Kent Beck, Author of first xUnit framework