File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes jUnit conceptual question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "jUnit conceptual question" Watch "jUnit conceptual question" New topic

jUnit conceptual question

chander shivdasani
Ranch Hand

Joined: Oct 09, 2007
Posts: 206

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.

Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

"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.

[My Blog]
All roads lead to JavaRanch
chander shivdasani
Ranch Hand

Joined: Oct 09, 2007
Posts: 206

Thanks. Now it makes sense to me
David Newton

Joined: Sep 29, 2008
Posts: 12617

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.
I agree. Here's the link:
subject: jUnit conceptual question
It's not a secret anymore!