I'm facing a nuisance when coding my unit tests using UnitTest++. I'm wondering how to access private member class fields in a clean way (or maybe any way...)
By now, I have a solution to access protected members using a class fixture deriving from the class under test. The following code shows the idea:
struct MyFixture : ClassUnderTest { };
TEST_FIXTURE(MyFixture, OneTest)
{
do_something();
CHECK(protected_field == true);
}
Nevertheless, I think this is not very clean, because problems relating inheritance could arise in some configurations and, anyway, just protected members can be accessed and tested.
I tried to declare test classes as friends, but as these are created in some special way by UnitTest++, I haven't managed to do it yet.
Does anyone have any idea of how to make test classes friends of the the classes under test?
Is there another way of approaching this problem in an easier or different way?
Thank you all in advance.