Click here to Skip to main content
12,243,182 members (23,726 online)
Click here to Skip to main content

Stats

41.8K views
877 downloads
44 bookmarked
Posted

ShortCUT - A Short C++ Unit Testing Framework

, 15 Feb 2007 CPOL
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);
        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.

You may also be interested in...

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