RE: [Cppunit-devel] REQUEST: throw user-defined errors in setUp() and tearDown()
Brought to you by:
blep
From: Moran Ben-D. <mbe...@ii...> - 2002-07-11 14:20:01
|
While we are on the subject.. Is there a way to set up a TestFixture once for all tests? For example, if my SetUp creates a database connection required by the tests in my fixture, it would be ideal if it only did so once. Moran -----Original Message----- From: Michel Armin [mailto:Arm...@si...] Sent: Thursday, July 11, 2002 3:23 AM To: cpp...@li... Subject: RE: [Cppunit-devel] REQUEST: throw user-defined errors in setUp() and tearDown() Is there a reason why we do not support assertion in setUp() and tearDown()? The code could be easily modified to support this. IMHO the general question is, what should be done in setUp() and tearDown() respectively. Personally, I use them to provide everything that is common to all test methods in a class. This also includes setting up a particular state of my (product code) environment that is a precondition for all the tests in a testcase class. And of course, this will lead to code that might fail (for whatever reason). Therefore I like the idea of being able to have asserts in the setUp() and tearDown() methods, because these would lead to a more precise error/failure message, why the test-methods couldn't be executed successfully. And locating bugs in our programs is the primary goal of this project, isn't it? Any other opinions? Regards Armin. > -----Original Message----- > From: Baptiste Lepilleur [mailto:gai...@fr...] > Sent: Mittwoch, 10. Juli 2002 19:44 > To: John Lam; cpp...@li... > Subject: Re: [Cppunit-devel] REQUEST: throw user-defined errors in > setUp() and tearDown() > > > It will be done. It goes along with the following TODO features: > > - Provide a mean for the user to catch 'custom' exception > in TestCase::run > (exception that do not subclass std::exception, such as > MFC CException, > or > RogueWave RWXMsg). > > That feature will likely result in a piece of code that will > run a specific > method, catching exceptions and assertion failures. This > should avoid that > so very long method... > > Though, notes that you usually try to avoid putting assertion > in setUp() and > tearDown() (though the memory/resource leaks detection is a > good candidate > for a tearDown assertions). > > Baptiste. > > ----- Original Message ----- > From: "John Lam" <jl...@iu...> > To: <cpp...@li...> > Sent: Friday, June 21, 2002 10:57 PM > Subject: [Cppunit-devel] REQUEST: throw user-defined errors > in setUp() and > tearDown() > > > If my setUp() or tearDown() methods fail, I would like to > have something > more specific than "setUp() failed ..." showing up in my > logs. I'd like > to propose the following change to TestCase.cpp: > > It currently reads: > > try { > setUp(); > > try { > runTest(); > } > catch ( Exception &e ) { > Exception *copy = e.clone(); > result->addFailure( this, copy ); > } > catch ( std::exception &e ) { > result->addError( this, new Exception( e.what() ) ); > } > catch (...) { > Exception *e = new Exception( "caught unknown exception" ); > result->addError( this, e ); > } > > try { > tearDown(); > } > catch (...) { > result->addError( this, new Exception( "tearDown() failed" ) > ); > } > } > catch (...) { > result->addError( this, new Exception( "setUp() failed" ) ); > } > > I would like to add: > > catch ( const Exception &e ) { > Exception *copy = e.clone(); > result->addError( this, copy ); > } > > to the outer most try block so that I can get more meaningful output > when errors occur. > > Similarly, I would like to add the same code to the try block that > guards the call to tearDown(). > > Does this sound reasonable to the community? > > Cheers, > > -John > http://www.iunknown.com > > > > > ------------------------------------------------------- > Sponsored by: > ThinkGeek at http://www.ThinkGeek.com/ > _______________________________________________ > Cppunit-devel mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppunit-devel > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Two, two, TWO treats in one. > http://thinkgeek.com/sf > _______________________________________________ > Cppunit-devel mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppunit-devel > ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek PC Mods, Computing goodies, cases & more http://thinkgeek.com/sf _______________________________________________ Cppunit-devel mailing list Cpp...@li... https://lists.sourceforge.net/lists/listinfo/cppunit-devel |