• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting started with jUnit

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to "Open Source Projects"
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic