To fix this I created a small Python script to add a new test, so working from the command line, I just need to write
newtest TestCase testMyNewTestand the declaration and prototype are created. I don't need to even look at the header file I can just go straight to the definition of the test function and add the test.
The header file for a CppUnit test case looks like this:
class TestCase : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( TestCase );
CPPUNIT_TEST( testSomething );
CPPUNIT_TEST( testNextBit );
CPPUNIT_TEST_SUITE_END();
public:
void setUp(); void tearDown();
void testSomething();
void testNextBit();
};
And the source file
CPPUNIT_TEST_SUITE_REGISTRATION( TestCase );
void TestCase::testSomething()
{
// test code here
}
void TestCase::testNextBit()
{
// test code here
}
The script is very simple, it searches for the last CPPUNIT_TEST macro in the header and adds a macro for the new test case. Searchs for the last test function, and adds a test after that. Then it adds a defintion at the end of the source file.
The script makes two assumptions
- The name of the class matches the name of the file. So the above test class would be in TestCase.h and TestCase.cpp
- The test class already has at least one test function when the script is run. Since I use a separate script to generate the boilerplate test class with a single test this is always true in my case.
The script is available here in case it is of use to anyone else: newtest.py
No comments:
Post a Comment