How do I run JUnit from NetBeans?

Posted by FarmBoy on Stack Overflow See other posts from Stack Overflow or by FarmBoy
Published on 2009-09-04T20:56:33Z Indexed on 2010/04/03 3:13 UTC
Read the original article Hit count: 579

Filed under:
|
|
|
|

I've been trying to understand how to start writing and running JUnit tests.

When I'm reading this article:

http://junit.sourceforge.net/doc/testinfected/testing.htm

I get the the middle of the page and they write, "JUnit comes with a graphical interface to run tests. Type the name of your test class in the field at the top of the window. Press the Run button."

I don't know how to launch this program. I don't even know which package it is in, or how you run a library class from an IDE.

Being stuck, I tried this NetBeans tutorial:

http://www.netbeans.org/kb/docs/java/junit-intro.html

It seemed to be going OK, but then I noticed that the menu options for this tutorial for testing a Java Class Library are different from those for a regular Java application, or for a Java Web App. So the instructions in this tutorial don't apply generally.

I'm using NetBeans 6.7, and I've imported JUnit 4.5 into the libraries folder. What would be the normal way to run JUnit, after having written the tests?

The JUnit FAQ describes the process from the Console, and I'm willing to do that if that is what is typical, but given all that I can do inside netbeans, it seems hard to believe that there isn't an easier way.

Thanks much.

EDIT: If I right-click on the project and select "Test" the output is:

init:
deps-jar:
compile:
compile-test:
test-report:
test:
BUILD SUCCESSFUL (total time: 0 seconds)

This doesn't strike me as the desired output of a test, especially since this doesn't change whether the test condition is true or not.

Any ideas?

© Stack Overflow or respective owner

Related posts about junit

Related posts about netbeans