UnitTesting
This document is under development by killerbot. Starting from 7 September 2009.
Introduction
This document will describe how unit testing can be combined with the Code::Blocks IDE. It will give a hands-on example on a unit testing framework and how it can be used with Code::Blocks.
What is Unit Testing
Simply put Unit Testing is the discipline and best practice of writing and running little test programs that test little units of code. Such a unit can be :
- a class
- a free function
- an interface
- ...
There are several unit test frameworks available to help you write, deploy, manage your unit tests. The most famous family is the xUnit framework, and some of it's descendants.
Why Unit Testing
Well we write code that implements some functionality. We need a way to check and prove that the implementation is correct. Therefor we need tests. We need tests on the application level, at the integration level of different components, classes, interfaces. But we also need tests for the smallest building blocks, the units. We also wans these tests to run very quickly. That we we can run the tests often, manually or automated. These tests will also be our safeguards during refactoring of the code, extending the code or whatever maintenance tasks we carry out on the code. These tests will also make us think of how our class, method, ... will be used. Since the test can be seen as a user of our code. Thanks do this, thinking about the tests before implementing the functionality can help us in the design : emergent design.