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