sshekhar1980
sshekhar1980

Reputation: 367

Junit 4 extend TestCase vs using combo of @Before/@After/@Test

With Junit 4 I am seeing that there are two ways of getting fixtures setup/teardown:

  1. Decorate setup/tearDown methods with @Before and @After respectively
  2. Extend TestCase and override setUp/tearDown

I am trying to understand why two different approaches to doing the same thing. Is it related to option 1 being introduced after Java 5 annotations while TestCase is legacy from pre Java 5? Or perhaps I am confusing the two.

Any help will be appreciated.

Upvotes: 0

Views: 365

Answers (1)

user1207289
user1207289

Reputation: 3273

The two approaches , as stated in this answer is because of what is introduced in Junit3 and Junit4. It also talks about why taking annotation way is better and its advantages.

If some of your testcase are wriiten in Junit3 way and now you want to use Junit4 but wondering how this can be done , then please have a look at this. It is explained there how tests, that are written old way, can be run with Junit4

Upvotes: 1

Related Questions