MoonUnit
 All Data Structures Variables Enumerations Enumerator Groups Pages
API Reference Manual

Overview

MoonUnit is a unit test framework for C and C++ which aims to reduce boilerplate code to an absolute mininum – you can add a new unit test to an existing library in about 2-4 lines of code and run it immediately. MoonUnit takes advantage of either symbol tables in shared objects or information gleaned directly from your source code to automatically identify and run unit tests without any additional bookkeeping.

Motivation

MoonUnit was conceived on the premise that unit testing is only effective if programmers feel that writing and maintaining tests is a worthwhile use of their coding time. When working on an interesting or demanding programming problem, taking time to write new tests and maintain or refactor existing ones can be an unwelcome context switch. Bothersome tests can find themselves disabled or commented out and begin to bitrot, quickly becoming dead weight.

In order to make writing unit tests as productive as possible, MoonUnit tries to adhere to the following design principles:

  • Brevity

    Introducing a new unit test takes a minimal amount of code. No copying and pasting templates, no mysterious incantions. Time is better spent writing test logic rather than slogging through boilerplate.

  • Centralization

    Information is located in precisely one place. No updating makefiles, test scripts, or lists of tests. Adding a test should involve editing exactly one place in one file.

  • Locality

    Tests can be close to the code they exercise and be compiled at the same time, immediately revealing any breakage after code changes. If any need updating or refactoring, they are always near at hand.

  • Reflection

    Tests are discovered and run automatically. You should never have to write your own harness or manually pack test objects into suites (although you can if you want to). The same ease that reflective languages like Python and Java lend to unit testing should be available in C and C++.

Getting Started

To learn how to write unit tests with MoonUnit, you can consult the detailed API documentation located in the unit test module. Or, you can learn by example.