• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JUnit 4 tests in Eclipse

 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running Eclipse 3.3 and it doesn't seem to be aware of Junit 4 test cases. It runs everything as a Junit 3 test case.

In Junit 3, the test methods had to start with "testXxxx()" and the test runner finds them using reflection. In Junit 4, you use an annotation (@Test) that can even take parameters like timeout, expected exceptions, .. See here for details http://junit.sourceforge.net/javadoc_40/index.html

But Eclipse doesn't recognize the @Test annotation. It is still looking for methods beginning with "test...()". This sucks because I would like to use the @Test(timeout=) feature.

I have Junit 4 library added to my project build path. What do I have to do to get this to work?

Thanks
Geoffrey
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the answer to my own question. If your test case extends junit.framework.TestCase (old Junit 3 way), then it will be treated as a Junit 3 test. When I removed the "extends TestCase" then it ran as expected in Junit 4.

Geoffrey
[ June 11, 2008: Message edited by: Geoffrey Falk ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic