File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Getting started with jUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Getting started with jUnit" Watch "Getting started with jUnit" New topic

Getting started with jUnit

Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Where is the app? I downloaded from sourceforge. I read the getting started article. I can't find the JUnit app. There's a gif image of the JUnit app in the Getting Started article. Where's the app? Is is a double clickable? Which directory? How do I use this %^&*@#%$ thing?
I'm tired of writing "public static void main" every time I try to debug, and Martin Fowler gave JUnit good reviews...
If there was a simple how-to or readme (one that actually gives instructions).

comp.lang.javascript FAQ:
Trish Wu
Ranch Hand

Joined: Oct 09, 2002
Posts: 34
Other than including junit.jar in your classpath, all the other things are just code (which is the beauty of Junit)
Isnt this documentation enough , plus the FAQ?
Other tutorial
I am beginning to use it in netbean, hope u find this link useful
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
The other tutorial looks good. The documentation is not enough, at least not for me. I like step 1 step 2 style instruction. I learn stuff by doing, not by some long-winded reasoning of why it's a good idea.
I already solved my problem by writing a main method to test the problem area. I'll get to that tutorial soon. [bookmarked]

Thanks Trish
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269

Where is the app?

Junit is not an application but a framework.

I'm tired of writing "public static void main" every time I try to debug, and Martin Fowler gave JUnit good reviews...

Junit is not a debugger but a unit testing and non-regression tool.
Junit itself will not prevent you from writing some code. But some plug-ins like the one referenced by Trish Wu (netbeans) will do some job for you, i.e. write the testing methods prototypes but you will have to write the code.
There is a professional tool called JTest which will do some automatic tests like passing a null argument or a negative value etc ...
Jeremy Thornton
Ranch Hand

Joined: Feb 21, 2002
Posts: 91
The JUnit cookbook steps through an example of how to use JUnit. Although it's not a step by step guide it'll give you enough info to get started.
Definitely worth sticking with for an hour or two. Will change the way you code - for the better.
In summary you just need to extend the TestCase class, fill in a set-up and tear-down method for initialising and killing anything you need for running the tests and implement some testX methods using the assertTrue(..) type methods. Then you need to pick a TestRunner (either text or GUI) create a TestSuite for running your test(s) and off you go.
Pretty trivial once you've done it a couple of times.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Moving to "Open Source Projects"

"JavaRanch, where the deer and the Certified play" - David O'Meara
Michael Matola
Ranch Hand

Joined: Mar 25, 2001
Posts: 1793
Awhile back in the refactoring forum folks started an OO calculator tutorial using JUnit to introduce refactoring and test-driven design. There's a sidebar thread on getting JUnit up and running.
It might be a bit tricky to follow the flow of the conversation as it bounces around several threads, but it was great fun to take part it.
XP123: XPlorations is another good place for info. The Test-First Stoplight is a good place to get started.
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Hey, that tutorial worked great. Really simple and basic. Just what I needed.
junit.swingui what I was seeing in the getting started article. The getting started article did not explain that.
Bill White
Ranch Hand

Joined: Oct 27, 2002
Posts: 82
Ok, now I am going to feel real stupid here... so here I go.
1) I set up a very simple test case
public void testMyUnderstanding()
assertEquals(20, 20);
ran the test (Integrated into VAJ 4.0) and got the following output:
Time: 0.981
OK (1 test)
So, I tried the same with assertEquals(20, 21);
and had the same output... You would think there would have been a failure reported. But there wasn't.
here is my setup code...
public static Test suite() {
return new TestSuite(Test_SWDBMealGroupManager.class);
public static void main(String args[]) {;
when I tried to use swingui or awtui I got compilation errors. Complaining that thier run methods dont expect and arg of type Test... Which it seems they should and do.
Any ideas?
I agree. Here's the link:
subject: Getting started with jUnit
jQuery in Action, 3rd edition