Re: [Cppunit-devel] order of construction, setUp, tearDown and destruction?
Brought to you by:
blep
From: Baptiste L. <bl...@cl...> - 2001-11-04 12:36:29
|
Here is what happen during a testing session: All test case are created when you call the TestFactoryRegistry method makeTest Only the constructor of each test case is called. A TestCase is created for each test method of your test class. When you run the test, for each test, the following sequence apply: - setUp() is called - If setUp() was sucessful (no exception thrown), the test method is called - if setUp() was sucessful, tearDown() is called (even if the test method failed You want to put the call to getTotalObject() in the setUp() method of your base class. And assert for equality in the tearDown() method of your base class. Look at TestCase::run(TestResult *result) for more details. Baptiste. ----- Original Message ----- From: "Graham, Ted" <Ted...@cs...> To: <cpp...@li...> Sent: Thursday, October 25, 2001 12:47 AM Subject: [Cppunit-devel] order of construction, setUp, tearDown and destruction? > > We are in the process of adopting cppUnit as our automated test framework > for a large suite of business objects. Our objects are reference counted, > so I want to check of how many object are in memory before and after each > test to make sure that neither the tests nor the code being tested are > leaking references. > > My understanding of a test cases's lifecycle used to be (from a doc I > wrote): > for( testClass = testClass1...testClass99 ) // every test class > for( test = test1...test99 ) // every test in that test > class > testClass thisTest; // e.g., CustomerTest > thisTest > testClass.setUp(); // virtual function, can be > overriden by testClass > thisTest.test() > testClass.tearDown(); // clean up anything that > was built in setUp > delete testClass; // the test class is > destroyed after each test. > > From debugging the framework, this doesn't seem to be the case. > Instantiation happens earlier, and tearDown and destruction are delayed > until after all tests have run. I have a object BaseTest that inherits from > CppUnit::TestCase and is the superclass to all our tests. > > Imagine I have a function getTotalObjects() that returns how many reference > counted objects are in memory. I'd like to call this in setUp and again in > tearDown and verify that it hasn't changed while the test was being run. > But I need to know what the lifecycle of test class is, and when setUp and > tearDown are called. Any help?? > > Thanks, > Ted > > _______________________________________________ > Cppunit-devel mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppunit-devel > |