Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@After annotation of Junit

 
Buddhika Mawella
Ranch Hand
Posts: 40
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to Junit and trying to execute following test. What I have understood is that if a method of a Junit test case is annotated with @After,
that method should run after every test method. I created below test class with Junit and it only print "inside @Test" when running. But according to my knowledge that should print both "inside @Test" and "inside @After". So whats wrong with this? help me.


Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Buddhika,
Since you are extending TestCase, JUnit is treating it as a JUnit 3.8 test. Which looks for setUp/tearDown/test* named methods.

If you remove the "extends TestCase", JUnit will see it as a JUnit 4 test and do what you expect.
 
Buddhika Mawella
Ranch Hand
Posts: 40
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne. Got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic