This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes JUnit 4 tests in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "JUnit 4 tests in Eclipse" Watch "JUnit 4 tests in Eclipse" New topic
Author

JUnit 4 tests in Eclipse

Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
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


Sun Certified Programmer for the Java 2 Platform
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JUnit 4 tests in Eclipse
 
Similar Threads
doubt in junit... first time user
How to create a "test suite" in JUnit 4
to use junit
What are the actual advantages of Junit4 over Junit 3 ?
assertNotSame pRmeters