This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Testing and the fly likes @After annotation of Junit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "@After annotation of Junit" Watch "@After annotation of Junit" New topic
Author

@After annotation of Junit

Buddhika Mawella
Ranch Hand

Joined: Jan 06, 2011
Posts: 39

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.


BM
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Buddhika Mawella
Ranch Hand

Joined: Jan 06, 2011
Posts: 39

Thanks Jeanne. Got it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: @After annotation of Junit
 
Similar Threads
When does hashCode gets Called !!
Outer-Inner Question
junit program
JUnit Test
method definition inside main...