• 1 reply
  • Latest Post - ‏2006-11-22T03:37:40Z by SystemAdmin
210 Posts

Pinned topic Unit testing - 'correct' idioms with Junit 3.8, JUnit 4 and TestNG

‏2006-11-14T00:26:34Z |
I am trying to evaluate JUnit 4 and TestNG, and have built classes that use the backwards compatibility of each to enable the reuse of existing JUnit 3.8 style test helper classes, (they exercise equals/hashcode/serializable/comparable and accessors).

Although each testcase works, I'm not entirely happy I am 'doing it right'.

To illustrate the frameworks, I have a toy class under test, (Person), and a testcase for each framework. I've posted this code up here:
for discussion and correction by anyone and everyone.

Would anyone mind having a look over the code and suggesting improvements?, I'd be most grateful.

Additionally I have attached the source (

Updated on 2006-11-22T03:37:40Z at 2006-11-22T03:37:40Z by SystemAdmin
  • SystemAdmin
    210 Posts

    Re: Unit testing - 'correct' idioms with Junit 3.8, JUnit 4 and TestNG


    Couple of points for you regarding the TestNG test-- you don't need to place the @Test annotation on both the class and its tests-- I find it easy to place it only on the class itself unless I have specific attributes I'd like to apply to a particular method (like grouping, etc).

    Setting junit=true means that the test will be run just like a JUnit style test-- in which case you don't need to follow TestNG idioms-- just follow traditional JUnit style conventions and TestNG will run the test just like JUnit would.

    For more info on TestNG, see and Cedric Beust's blog at