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: http://javaunittest.pbwiki.com/
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 (TestSpikes.zip).
This topic has been locked.
1 reply Latest Post - 2006-11-22T03:37:40Z by SystemAdmin
Pinned topic Unit testing - 'correct' idioms with Junit 3.8, JUnit 4 and TestNG
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2006-11-22T03:37:40Z at 2006-11-22T03:37:40Z by SystemAdmin
SystemAdmin 110000D4XK210 PostsACCEPTED ANSWER
Re: Unit testing - 'correct' idioms with Junit 3.8, JUnit 4 and TestNG2006-11-22T03:37:40Z in response to SystemAdminChris-
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 http://www.testng.org and Cedric Beust's blog at http://beust.com/weblog/.