Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit Tests DEFINITION AND OVERVIEW by Paul M. code of the damned. com.

Similar presentations


Presentation on theme: "Unit Tests DEFINITION AND OVERVIEW by Paul M. code of the damned. com."— Presentation transcript:

1 Unit Tests DEFINITION AND OVERVIEW by Paul M. code of the damned. com

2 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. 295

3 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 Test Harness System Under Test (SUT)*: Industry standard term to indicate the targeted test component, class, function, module etc.

4 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.

5 What to Do Use a unit test framework Isolate your code (SUT) to develop, compile and run in an independent test harness* The developer writes the tests as they develop the SUT Verify 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

6 What to Avoid Do not delete tests Do not comment out tests Do not write the tests outside of the prescribed test framework Your tests must run without specialized hardware Your tests must not require manual interaction Do not print directly to the console; Use the test frameworks output APIs and only for errors Avoid the use of expensive resources

7 Qualities and Benefits The software becomes more correct, reliable, and robust Instills confidence in the developer of the software ◦Provides 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 Project 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.

8 Resources Code of the Damned ◦The Purpose of a Unit TestThe Purpose of a Unit Test ◦Unit Test FrameworksUnit Test Frameworks ◦Test Driven DevelopmentTest Driven Development Books ◦xUnit Test Patterns: Refactoring Test CodexUnit Test Patterns: Refactoring Test Code by Gerard Meszaros ◦Working Effectively with Legacy CodeWorking Effectively with Legacy Code by Michael C. Feathers, Author of CppUnit(Lite) ◦Test Driven Development: By ExampleTest Driven Development: By Example by Kent Beck, Author of first xUnit framework


Download ppt "Unit Tests DEFINITION AND OVERVIEW by Paul M. code of the damned. com."

Similar presentations


Ads by Google