From: Eric Hodel Date: 2004-07-14T23:09:03+09:00 Subject: Re: instance variable question in test/unit TestCase --CqfQkoYPE/jGoa5Q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Nicholas Van Weerdenburg (nick@activehitconsulting.com) wrote: > Hi all, >=20 > test/unit is super cool.I was blown away by how test/unit automatically= =20 > looks in ObjectSpace and creates a test suite for all tests found, and=20 > then runs them. I was wondering how it was possible, so I looked at=20 > unit.rb- >=20 > at_exit{exit(Test::Unit::AutoRunner.run($0)) unless($! || Test::Unit.run?= )} >=20 > Cool! >=20 > A couple of questions: >=20 > 1. A more general question: how do I initialize instance variables=20 > without an "initialize" method? In my test case, I want instance=20 > variables, but placing "@myvar=3D1" outside a method doesn't seem to work= =20 > ( I dimly recall that this is a class instance variable or something=20 > like that). The reason I want to do this is that in subclassing=20 > Test::Unit::TestCase I don't know offhand what it's initialize method=20 > looks like (a no arg "initialize" gives an argment number error) and=20 > don't want to learn just for this reason. Use the setup and teardown methods. Here's how a test case gets run: test_case =3D YourTestCase.new test_case.setup test_case.test_something test_case.teardown (A fresh, new YourTestCase instance is created every time.) > My other option is the setup method, since that is called for before all= =20 > test methods. Are there any other options? Yes :) > 2. where do I find the will to return to programming in Java now that=20 > I'm having so much fun in Ruby? You can find a unit test suite for Java, and write code in Groovy. Word on the street says Groovy is much like Ruby. --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --CqfQkoYPE/jGoa5Q Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQFA9T58MypVHHlsnwQRAk+kAJ4/iwMjdkWZsOOc3Ir6qPqXEtuiZACeLuio DFghXQWIyP4OGLCBb2VcNAI= =60bu -----END PGP SIGNATURE----- --CqfQkoYPE/jGoa5Q--