This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jUnit conceptual question

 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have recently starred using jUnit to write test cases. While, googling for tutorials, i came across two approaches to write test cases:

> Using Annotations (@Test)
> Extending TestCase class

However, i never could find the possible differences between them, and what i should be using in my code. I know, extending TestCase class is not a suitable option, since i cant extend anyother class if i do this. Can anyone provide me with more differences, preferably the scenarios where i should use particular implementation.

 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Extending TestCase" is the old way to do it, but it's still being used. Annotations were introduced since JUnit 4. The advantage is that you can annotate any method to be setUp, tearDown and test methods. The biggest difference I think is that, to use annotations, you'll need at least Java5. If you're stuck with Java1.4 or less, the only way to mark your tests is by extending TestCase.
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Now it makes sense to me
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One issue is that if you're forced to extend TestCast you can't extend anything else--that may or may not be an issue for any particular test.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic