I'm using UnitTest++ for unit testing C++ code.
In my tests, there's a group of tests I repeat several times. What I'd like is for a utility function to perform these tests. In short, I'd like to take this:
TEST( foo ) {
Foo one;
Foo two;
// init one & two
// lots of CHECK_CLOSE(one.bar, two.bar, 1e-5); in repeating cycles
}
TEST( bar ) {
Foo one;
Foo two;
// init one & two
// lots of CHECK_CLOSE(one.bar, two.bar, 1e-5); in repeating cycles
}
And use this:
void blah( const Foo& one, const Foo& two ) {
// lots of CHECK_CLOSE(one.bar, two.bar, 1e-5);
}
TEST( foo ) {
Foo one;
Foo two;
// init one & two
blah(one, two);
}
TEST( bar ) {
Foo one;
Foo two;
// init one & two
blah(one, two);
}
This doesn't work due to UnitTest++'s macro manipulations. What is the best way to approach this problem?
edit: A couple of thoughts which I can't check out right now.
- If I use a fixture, with the utility function in the
struct
, will I be able to call UnitTest++ macros from within this function? - I can write a macro to perform the common tests. I don't really like this, but at least I'll stary dry...