Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting started with jUnit

 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Trish Wu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Documentation
Other tutorial
I am beginning to use it in netbean, hope u find this link useful
junit-netbeam
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ...
W.
 
Jeremy Thornton
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to "Open Source Projects"
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1820
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, that tutorial worked great. Really simple and basic. Just what I needed.
junit.swingui
...is what I was seeing in the getting started article. The getting started article did not explain that.
 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
and
public static void main(String args[]) {
junit.textui.TestRunner.run(suite());
}
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic