TDD in C++. Getting warmer

This afternoon I punched through a major wall (a couple posts down) that was preventing me from doing what I wanted to do here. I’ve been working (at about a 33% pace, what with all the hippy taunting and such I’ve been doing. It IS Saturday Night after all.)

The goal is in sight. I may very well be able to simplify this some more. But here, WITHOUT MACRO MAGIC is the first “live use case” of my C++ unit testing framework.



class MyTestSuite : public BaseTestSuite<MyTestSuite>
{
public:
MyTestSuite(const std::string& suite_name)
:BaseTestSuite<MyTestSuite>(this,suite_name)
{
}

void test_test()
{
assertEqual("Hello World!","Hello World!");
}
protected:
virtual void register_tests()
{
register_test("test_test",&MyTestSuite::test_test);
}
};


The shell is trivial…


int main(void)
MyTestSuite newSuiteTests("NewSuiteTests");
newSuiteTests.run();
newSuiteTests.post_mortem();
return 0;
}


Yes. I’m irrational. I hate macros more than I hate GOTO. They’re cheating.

The goal, more clearly stated is to be able to create an xUnit test class with “simple as possible” method tests. C++ being C++ means you must intentionally register the methods themselves.

Yes, the register method is messier than I’d like. I could get rid of the “test_test” parameter by using RTTI but frankly, the farther I can get without opening that can of worms, the better.

Yes, the constructor is a bit messier than I’d like. Currently it’s “the easiest thing that does the trick.”

People who understand C++ will at least get why I’m doing all those things.

Now, more cleanup, more of the framework’s unit tests migrated into the new suite architecture and a few more bits of functionality.

The goal is a production-ready release on April 1, with documentation, etc.

Oh yeah, the library’s about 10k spread across 2 header files.

Tags: , , ,

Leave a Reply