CxxTest/cxxtest — Issue #31: Add the ability to annotate tests/cases/suites with attributes
Author: whart222
Created: 2012-02-04 18:11:57+00:00
State: open

I would like the ability to annotate tests, cases, and/or suites with arbitrary
attributes that could be used to select tests to execute at run time. For
example, a test could be marked with an attribute "long_running" to indicate it
takes some time to run. Or, a test could be marked as a "smoketest". The user
could set up their build process perform a quick verification of the build by
executing only those tests marked with "smoketest".

One way it might look to the unit test developer:#ifndef __DELTATEST_H
#define __DELTATEST_H

#include
#include

class DeltaTest : public CxxTest::TestSuite
{
double _pi, _delta;

public:
void setUp()
{
_pi = 3.1415926535;
_delta = 0.0001;
}

void testSine() TS_ATTRIBUTES(smoke,integration)
{
TS_ASSERT_DELTA( sin(0.0), 0.0, _delta );
TS_ASSERT_DELTA( sin(_pi / 6), 0.5, _delta );
TS_ASSERT_DELTA( sin(_pi / 2), 1.0, _delta );
TS_ASSERT_DELTA( sin(_pi), 0.0, _delta );
}
};

#endif // __DELTATEST_H

The test generator would use the comma separated values inside TS_ATTRIBUTES as
a list of attributes and make the appropriate decorations. TS_ATTRIBUTES itself
could be defined as an empty macro for the purposes of preprocessor processing.