Click here to Skip to main content
13,550,805 members
Click here to Skip to main content


44 bookmarked
Posted 15 Feb 2007
Licenced CPOL

ShortCUT - A Short C++ Unit Testing Framework

, 15 Feb 2007
A very simple, customizable unit-testing framework for C++ developers
#ifndef _UNITTEST_H_
#define _UNITTEST_H_

// A basic test suite with a 'resource' for the tests to use
struct MySuite1 : TestSuite
    MySuite1() : resource(0) {}
    virtual void setup()    { resource = 1; }
    virtual void teardown() { resource = 0; }
    int resource;

// A test case in plain ole C++
struct MySuite1Test1 : TestCase
    const char* name() { return "Test case 1"; }
    void test(TestSuite* suite) 
        MySuite1* data = static_cast<MySuite1*>(suite);
        // throw TestMessageException("manual exception");

// A test case that uses some helper macros
struct MySuite1Test2 : TestCase
    T_NAME("Test case 2")
    void test(TestSuite* suite) 
        T_DATA(data, MySuite1, suite);
        T_ASSERT(1 == 0); 

// A test case with macros turned up to 11
T_TEST(MySuite1, MySuite1Test3)
    T_ASSERT(1 == 1); 

#endif _UNITTEST_H_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
I work as a developer in the Seattle area. I am currently residing in France.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180515.1 | Last Updated 16 Feb 2007
Article Copyright 2007 by Todd-Lucas
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid