Unit testing is the process of checking that a small component of a program gives the desired output given a series of inputs. This breaks down the large project into smaller goals. This is an important part is an important part of program development. It allows us to assure that our program is behaving as designed. Whenever a reproducible error comes up where a bad input breaks the code, it is a good idea to add that bad input as a test case.
This is closely tied to regression testing. Regression testing is the process of making sure that newly written code does not have a negative impact on existing functionality. It is a good idea to incorporate all unit tests into regression tests to ensure that they work of the rest of the project's development.
One approach to development that I support is test-driven development. In this method, you write a suite of tests before programming that test the desired operation of the program or function. This is effective because it forces you to clearly define what should happen on a variety of inputs before beginning to code and can help identify how to edge cases such as null input.
CxxTest is a testing framework for C++ written in Perl. When it runs, it displays how many tests have passed and which tests failed. I like it because it is easy to write a test suite using TS_ASSERT() statements in a class that inherits from CxxTest in a header file. It is easy to create an automatic test script that can be run during development to get an indication of progress made.
Unit testing, however, is not a silver bullet to developing good code. A program is designed to run on any potential input, but we are only able to test a finite subset of these potential inputs. One of the weaknesses of testing is it relies foresight of the programmer to think of potentially bad inputs. Another is that is possible to pass a series of tests and still not work as intended.

Recent Comments