Re: [Cppunit-devel] Question on TestSuite::addTest() and Test Fixture instantiation
Brought to you by:
blep
From: Baptiste L. <gai...@fr...> - 2003-04-06 09:55:35
|
JUnit behave the same way. This ensure test case isolation. CppUnit 2.x will support this way of implementing test suite (even though it is ill advised, it is useful for performance when implementing some functionnal tests). Here is one way to get this to work in CppUnit 1.9.10 (rough sketch): After CPPUNIT_TEST_SUITExxx: - create the fixture that will be shared between the tests. Use a smart-pointer to manage its life time. - subclass TestCaller and pass the smart-pointer to the subclass. Use by reference constructor of TestCaller. - introduce new helper macros that replace the CPPUNIT_TESTxxx macros. This new macros should use the subclassed TestCaller. As you see it's not trivial. Baptiste. PS: notes that TestSuiteBuilder does not exist anymore. ----- Original Message ----- From: "Mark Winrock" <mwi...@ie...> To: <cpp...@li...> Sent: Friday, April 04, 2003 11:39 PM Subject: [Cppunit-devel] Question on TestSuite::addTest() and Test Fixture instantiation > Hi, > > A work colleague noticed that her test classes were getting instantiated > once per test method when using the helper macros > (as in the heirarchy demo). We are using CppUnit 1.8.0. I had assured her > that this was probably a bug, and I would look into > what might be causing it. I was under the impression, with the "xUnit" > frameworks, that the "fixturing" gets instantiated once per suite of test > methods on that fixture. But, after looking into the 1.8.0 helper macros, > TestSuiteBuilder and TestCaller, I find this is done by design. > > Our goal is to have the ability to have a persistent resource, or to have a > single task performed, that can be used across the set of test methods on > the fixture. This may seem contrary to setUp()/tearDown(), but often there > is a dependent piece of work that would push the test times out > extraordinarily long, or take up too much resources, if done more than once > per fixture. It had been our intention to do this in the constructor of the > fixture. > > I have investigated using derivations of TestSuiteBuilder, > TestFixtureFactory, and TestCaller, but I am hopefull there is a simpler way > and I'm just too dense to recognize it just now. Do you have any suggestions > on how we might readily accommodate that goal in CppUnit? > > Thanks! > > Mark Winrock > mwi...@ie... > Software Test Engineer |