The Enbridge Inc. "CUT" C++ Unit Test Framework

CUT is designed to make C++ unit testing as simple as possible, without sacrificing the ability to handle complex C++ constructs such as exceptions, templates and threads.

In particular, it avoids most (if not all) of the painful reasons that people don't do unit testing in C++.

Unlike other C++ unit testing frameworks, CUT:

How-to

Here is a complete standalone CUT unit test, which actually runs its unit tests as CGI HTML, or as plain text. See cut.H for more detailed instructions.

#include <cut>
#include <iostream>

namespace cut {
    test                        root( "How-To Tests" );

    CUT( root, FirstSuite, "The First Suite" ) {
        assert.out() << "Success: " << name() << std::endl;
        assert.ISTRUE( true );
    }
}

int
main( int, char ** ) {
    bool success;
    if ( getenv( "REQUEST_METHOD" )) {
        // 
        // Lets run our tests with CGI HTML output:
        // 
        //                            target  sparse  flat   cgi
        //                            ------  ------  ----   ---
        success = cut::htmlrunner( std::cout, false,  true,  true ).run();
    } else {
        // 
        // But, here's the (simpler) textual output:
        // 
        success = cut::runner( std::cout ).run();
    }
    return ! success;
}

Now, lets imagine that you wanted to add a couple more unit tests, in some other compilation unit. All you would do is add the following code to that file (note that you can use either assert.out() or std::cout to log test suite output, but you should probably be consistent; assert.out() goes to whatever std::ostream was passed to the cut::runner):

#include <cut>

namespace cut {
    CUT( cut::root, SecondSuite, "The Second Suite" ) {
	assert.out() << "Failure: " << name() << std::endl;
	assert.ISTRUE( false );
    }

    CUT( cut::root, ThirdSuite, "The Third Suite" ) {
	std::cout << "Unknown: " << name() << std::endl;
	assert.ISUNKNOWN( true );
    }
}

That's it! No other house-keeping is required. If the second compilation unit is linked, its tests will also be linked, and they will all be run.

Examples

Click the following link to generate the output of the above unit tests (remember, all tests are run 3 times, here, and all tests are output. Normally, only non-successful tests would be output):

http://enbridge.kundert.ca/cgi-bin/cut/test-twofiles

Here is the output from another CUT unit test. Once again, all of the unit tests are run multiple times, and output in several different forms:

http://enbridge.kundert.ca/cgi-bin/cut/cut-test

Finally, here is the unit test suite for the enbridge REF Reference Counting Pointer Framework, which runs about 2.2 million individual test cases. Remember, all of these tests are actually being run when you click these links, and are generating the HTML output you see!

http://enbridge.kundert.ca/cgi-bin/ref/ref-test

Download

The latest version is always available in the cut-#.#.#.tgz file, here

Copyright (C) 2004,2005 Enbridge Inc.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.