tags:

views:

2279

answers:

5

What GUI should use to run my JUnit tests, and how exactly do I do that? My entire background is in .NET, so I'm used to just firing up my NUnit gui and running my unit tests. If the lights are green, I'm clean.

Now, I have to write some Java code and want to run something similar using JUnit. The JUnit documentation is nice and clear about adding the attributes necessary to create tests, but its pretty lean on how to fire up a runner and see the results of those tests.

+2  A: 

There's a standalone JUnit runner that has a UI, but I recommend using one of the builtin test runners in the Java IDEs (Eclipse, Netbeans, and IntelliJ all have good ones). They all support JUnit, and most support TestNG as well.

jodonnell
+1  A: 

Eclipse is by-far the best I've used. Couple JUnit with a code coverage plug-in and Eclipse will probably be the best unit-tester.

jjnguy
A: 

Why you need a GUI runner? Can't you just run the tests from the IDE itself?

In .Net we have TestDriven.net, in Java there must be something equivalent. You can check out IntelliJ IDEA, it has the unit testing support built-in.

Ngu Soon Hui
A: 

We use Eclipse for development, and it had not dawned on me that there might be a something in Eclipse itself since I was so used to the NUnit standalone GUI. I've got what I need, thanks everyone.

A: 

JUnit stopped having graphical runners following the release of JUnit 4.

If you do have an earlier version of JUnit you can use a graphical test runner by entering on the command line[1]:

java junit.swingui.TestRunner [optional TestClass]

With the optional test class the specified tests will run straight away. Without it you can enter the class into the GUI.

The benefits of running your tests this way is that you don't have the overhead of an entire IDE (if you're not already running one). However, if you're already working in an IDE such as Eclipse, the integration is excellent and is a lot less hassle to get the test running.

If you do have JUnit 4, and really don't want to use an IDE to run the tests, or want textual feedback, you can run the text UI test runner. In a similar vein as earlier, this can be done by entering on the command line[1]:

java junit.textui.TestRunner [TestClass]

Though in this case the TestClass is not optional, for obvious reasons.

[1] assuming you're in the correct working directory and the classpath has been setup, which may be out of scope for this answer

Grundlefleck