views:

527

answers:

8

I've recently been lifted out of the .Net world into the Java world and I miss my unit tests.

Using Visual Studio I used NUnit and TestDriven.net to run my unit tests.

What is a comparable system for Java Using Eclipse?

I'm looking specifically for the plugins that will get me going, or a guide on how to do it.

I'm aware that JUnit is what NUnit was initially based on, but I want to know the best way to integrate it into Eclipse as there seem to be a few plugins that do this and I don't have the time to play around with them all.

UPDATE

Okay I didn't know that JUnit was built into the IDE. Are there any plugins that make using JUnit any easier?

+3  A: 

Which version of Eclipse are you using?

For as long as I remember (I've been using Eclipse since early 3.xs), Eclipse supports JUnit out of the box. You just:

Right-click on a project -> Run As -> JUnit Test

Does this not work for you?

Jack Leow
I'm using Europa. And I didn't know that it was built into the IDE, thats pretty cool.
Omar Kooheji
Unit Testing and refactoring IDE-support evolved like Smalltalk > Java > .Net n the rest now
Gishu
+8  A: 

Using JUnit with eclipse is actually very easy. Just go to File->New... and select JUnit Test Case. Eclipse will handle adding the JUnit library and all of the imports.

pkaeding
A: 

Easier than "Right-click on a project -> Run As -> JUnit Test"? Like you want it bound to a keypress (because it probably is). Lemme check--Yeah, alt-shift-X, then "T". Easy enough?

There is also window/show view/other/java/JUnit that will give you a junit run bar in a window. You can then just hit the run tests button and it will run all the tests in your project/section.

Ctrl-shift-L is great for figuring out keybindings if you are getting to know eclipse.

Also, get VERY familiar wtih ctrl-space, just press it whenever you're in the middle of typing something (seriously, try it with everything!) Also type "sysout[ctrl-space]"

Bill K
@BillK: save two more keypresses "syso[CTRL + SPACE]" :)
_ande_turner_
+1  A: 

I've been using moreUnit for a few years and can't live without its Ctrl+J shortcut to switch between the class and its test case.

I've also found EclEmma useful for finding untested code.

qualidafial
A: 

I've used the testNG witch has a plug in for eclipse.

Henrique
A: 

JUnit 4 is actually really easy to use, as long as you're using a project that targets Java 5 or newer, and have added it to the project.

I mean, how much easier can you get than

@Test
public myTest() {
    // Test code here
}

There are also @Before, @After, @BeforeClass, @AfterClass, and @Ignore. The *Class methods need to be static methods. @Before runs before each test, @BeforeClass runs before the first test... but keep in mind that JUnit tests can run in any order.

If you're doing database tests, you may want to look into the DBUnit addon, although you need to take some special steps to use it with JUnit 4's native mode.

R. Bemrose
A: 

fit (http://www.theserverside.com/news/thread.tss?thread_id=39417)

dbunit (http://www.dbunit.org/)

many others

in eclipse, you can right click a package and select run as a junit test.

be careful of http://xunitpatterns.com/test%20fixture%20-%20ambiguous.html. iirc, this boils down to junit creating an instance of each test case before calling setup and nunit just creating one instance.

Ray Tayek
A: 

What do you mean with "make using JUnit any easier"?

I use Ant for runnings tests as a task. Output will be stored into a flat file or a html file. It depends on the TestRunner.

Please specify your question and you'll get answers! :)

furtelwart