Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

ShortCUT - A Short C++ Unit Testing Framework

, 15 Feb 2007
A very simple, customizable unit-testing framework for C++ developers
shortcut_demo.zip
shortcut_demo
shortcut.exe
shortcut_src.zip
shortcut_src
#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);
        data->resource++;
        // 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);
        data->resource++;
        T_ASSERT(1 == 0); 
    }
};

// A test case with macros turned up to 11
T_TEST(MySuite1, MySuite1Test3)
{
    data->resource++;
    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.

License

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

Share

About the Author

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 16 Feb 2007
Article Copyright 2007 by Todd-Lucas
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid