Domanda

We have a number of CPPUNIT test suites, and each suite of tests will have their own setUp()/tearDown(), what I am looking to do is have a common setUp()/tearDown() across all of the suites. As I understand it for a given suite I have a setUp() and Teardown() that is run prior to each test in the suite

e.g. for suite A we have:

suiteA - setUp();
suiteA - test1();
suiteA - tearDown();
suiteA - setUp();
suiteA - test2();
suiteA - tearDown();
....

and for suite B we would have:

suiteB - setUp();
suiteB - test1();
suiteB - tearDown();
suiteB - setUp();
suiteB - test2();
suiteB - tearDown();
....

What I'd like would be something like is something like

commonSetUp();
suiteA - setUp();
suiteA - test1();
suiteA - tearDown();
commonSetUp();
suiteA - setUp();
suiteA - test2();
suiteA - tearDown();
commonSetUp();
suiteB - setUp();
suiteB - test1();
suiteB - tearDown();
commonSetUp();
suiteB - setUp();
suiteB - test2();
suiteB - tearDown();
È stato utile?

Soluzione

We solve the problem by not using cppunit::TestFixture directly. We have several classes inheriting from cppunit::TestFixture that implement setUp and tearDown (and also provide some common test code). Each test class now inherits from one of our own classes doing the setUp and tearDown.

If necessary you can overwrite the setUp/tearDown later in a class and if necessary call the base class setUp/tearDown.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top