Re: [Pyunit-interest] Unit testing constructors
Brought to you by:
purcell
From: Changjune K. <jun...@or...> - 2002-01-30 04:15:27
|
<html> <body> <img src=3D"http://user9.orgio.net/orgiomail/button.php3?id=3Dimyyudwfzhw= zpgjtfuj&user=3Djuneaftn" width=3D"1" height=3D"1"> <pre> It's simple and easy. -------- import unittest class J: def __init__(self,someArg1,someArg2): if someArg1<0 or someArg2<0: raise Exception print "foobar!" class TestJay(unittest.TestCase): def testBounds(self): self.assertRaises(Exception, J, -30, 20) if __name__=3D=3D'__main__': unittest.main() --------- ----- Original Message -----=20 From: "Sean Allen" <ze...@wo...> To: "PyUnit" <pyu...@li...> Sent: Wednesday, January 30, 2002 9:00 AM Subject: [Pyunit-interest] Unit testing constructors Hello, sorry if this has been covered before Currently, I am trying to implement a test suite for some objects. The objects need to do bounds checking based on arguments to their __init__() ctor. If the object is given initialization parameters that are out of bounds, an Exception must be thrown. So far, So good. I am having a great deal of difficulty trying to get a test case to work that does something like (pseudo code) ... self.assertRaise(Exception, (attempt to create the object), (args)) ... which basically tells me I have to supply an instance of the object I'm trying to create as first argument, which is not really possible under these conditions. The code works well in interactive testing, it's just how to write the unit test Any ideas? =20 Sean Allen </pre> </body> </html> <br> --------------------------------------------------------<br> Best Free e-Mail Site Orgio.net <a href=3D"http://www.orgio.net/" target=3D= "_blank">http://www.orgio.net</a><br> =C6=C4=BF=F6=C0=AF=C0=FA=B0=A1 =BC=B1=C5=C3=C7=D1 =B8=DE=C0=CF 30M =B9=AB= =B7=E1 =C0=FA=C0=E5=B0=F8=B0=A3, =BC=F6=BD=C5=C8=AE=C0=CE=C0=C7 =BF=F8=C1= =B6 |