Re: [Cppunit-devel] Bug or misunderstanding?
Brought to you by:
blep
From: Baptiste L. <gai...@fr...> - 2003-01-23 22:46:59
|
----- Original Message ----- From: "Duane Murphy" <dua...@ma...> To: "Baptiste Lepilleur" <gai...@fr...>; "CppUnit Developers" <cpp...@li...> Sent: Wednesday, January 08, 2003 5:35 PM Subject: Re: [Cppunit-devel] Bug or misunderstanding? > --- At Tue, 7 Jan 2003 10:38:34 +0100, Baptiste Lepilleur wrote: > > >> > >> Others that work on CppUnit can speak up for why it is this way. I have > >> long considered this a bug. CppUnit likes calling new() :-). They > >> instiate a new Fixture() for each test case. You will have to work around > >> it somehow. > > > >This is a normal behavior. It provides maximum isolation between each test > >case of the fixture. As far as I know JUnit behave the same way. > > There is a chance I missed something, but from my brief review of the > JUnit code and especially the JUnit articles and examples I have read, it > appeared to me that the point of the Fixture was indeed to manage the a > set of tests and not a single test. If it was meant to manage a single > test that what is the point of setUp() and tearDown()? I could just as > easily do these in a constructor or a destructor. I believe you're mistaken concerning JUnit. Give a look at TestSuite.createTest(), and you'll see that the constructor is called for each test (there is no choice, since the name of the method to be called is stored in the test case name (see TestCase documentation)...). It could indeed be the constructor and destructor, but using virtual method is more flexible: - setUp/tearDown can be called multiple time (that is what is done when you click the 'run' button in the MFC/QT test runner). - setUp and tearDown can call virtual method, which are implemented in subclass. This is not possible in constructor/destructor. That being said, I think it will be possible to support both mode in CppUnit 2.0: using a single fixture instance is indeed useful when initialization cost much. > >> CppUnit likes calling new() :-). > > > >What do you mean ? > > I find the use of new() to be a liability. It is the leading cause of > memory leaks and object lifetime errors. I have in fact had bugs with > CppUnit where the lifetime of an object was indeed shorter that I had > expected. > > I avoid pointers and unmanaged memory as much as possible. I use > references and shared pointers (from boost) for all of my memory > management. This makes the code safer, more stable, and easier to read > and understand. I believe you meant to say "CppUnit use delete a lot" ;-). I'm also a fair user of boost and boost::shared_ptr. CppUnit 2.0 makes use of smart-pointer. In fact, I borrowed the 'no template member' shared_ptr implementation and modified it to be more portable and provide a static_cast. For instance, the TestFactoryRegistry code is much simpler (doesn't have all that memory management code). > I view projects like CppUnit() as "industry examples." Maybe this is too > strong of an expectation, but I would expect to see "best practices" in a > widely used framework like CppUnit. I view memory management as a best > practice. Keep in mind that I'm still fairly young to the world of C++. I started learning 5 years ago, and I only have 3,5 years of professionnal experience. I learned a lot during the last year, and I believe some of this will be reflected in CppUnit 2.0. Anyway, I intend CppUnit 2.0 to go through a review phase when I'll have a basic version done, so features/style... can be discussed at length. Baptiste. > > ...Duane |