File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unit Testing/JUnit what do we use them for?

 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been using Java for awhile now, and I've never used ANT or JUNIT, but I've heard a lot about them. Just curious if someone can explain why we use them, and maybe some informational sites about them? I read a bit of wiki to see about unit testing, but it really didn't explain it much, so I'm curious why we use them...

Thanks!


EDIT: Reading more into it it seems like it's meant to set rules for the code to complete in order to see if everything works correctly? If it doesn't complete it then it will give errors or exceptions? Seems interesting...
 
Junilu Lacar
Bartender
Pie
Posts: 6536
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look around for articles on Test-Driven Development and Refactoring. JUnit came out of a need to support these practices. These two practices are the most compelling reasons for doing unit testing, IMO.
 
Junilu Lacar
Bartender
Pie
Posts: 6536
21
Java Linux Mac Scala Spring
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I'm not sure if I would have use for it, though it doesn't hurt to try. It seems like it's good to test multiple things, for instance on the wiki page it uses the assert keyword to test if a+b = c. is assert only used in testing? I've seen it, but never used it.

thanks!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay,
assert or assertTrue()? The former is a keyword in Java. The later is used in JUnit testing. a + b = c is a trivial assert though. Probably just for the sake of example.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Jay,
assert or assertTrue()? The former is a keyword in Java. The later is used in JUnit testing. a + b = c is a trivial assert though. Probably just for the sake of example.


Yeah it was assertTrue() http://en.wikipedia.org/wiki/Unit_testing shows the a+b example . From speaking with the person who's code I'm rewriting I don't think I will need to do unit testing, as it's a gui where you can mostly see what's going on, but maybe Junit wil have some uses, I'm not sure, any comments are appreciated though .


Also what's up with Ant and Maven? They are Automated build tools or...? What exactly are there purposes(is this the right forum to ask)? Thanks all!!!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While it is possible to unit test a GUI, it isn't easy and certainly isn't a starting point for learning about unit tests. Sometimes, you'll extract logic to a method independent of the GUI and unit test that.

Ant and Maven are build tools. They can create your jar file for distribution. It saves you the time of setting up the classpath, compiling, running unit tests, running a tool to check coding standards, etc. You just kick off the build script and it repeats that process.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:While it is possible to unit test a GUI, it isn't easy and certainly isn't a starting point for learning about unit tests. Sometimes, you'll extract logic to a method independent of the GUI and unit test that.

Ant and Maven are build tools. They can create your jar file for distribution. It saves you the time of setting up the classpath, compiling, running unit tests, running a tool to check coding standards, etc. You just kick off the build script and it repeats that process.


I see... Netbeans does a lot of that stuff for me already, though not the unit tests nor the tools like you said about code standards(I don't think...) Seems like I should check into those, I know I have both Ant and Maven plugins installed.



Thank you!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Netbeans actually uses Ant behind the scenes. You can read part of the build.xml in the project. It's not as clear as one you'd write yourself, but effective.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Netbeans actually uses Ant behind the scenes. You can read part of the build.xml in the project. It's not as clear as one you'd write yourself, but effective.


Yeah I see it go off when I build it and compile, cool stuff.... Not sure when I'll look into it myself, but for now it seems that Netbeans does enough for me.... Not sure how important Ant/Maven is to the finishing of programs.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Orsaw wrote:Yeah I see it go off when I build it and compile, cool stuff.... Not sure when I'll look into it myself, but for now it seems that Netbeans does enough for me.... Not sure how important Ant/Maven is to the finishing of programs.

It's not critical when you are just doing projects on your own. When you need a repeatable build for production/a big team or find yourself doing multiple steps to build is when you need it.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:
Jay Orsaw wrote:Yeah I see it go off when I build it and compile, cool stuff.... Not sure when I'll look into it myself, but for now it seems that Netbeans does enough for me.... Not sure how important Ant/Maven is to the finishing of programs.

It's not critical when you are just doing projects on your own. When you need a repeatable build for production/a big team or find yourself doing multiple steps to build is when you need it.


Yeah, makes sense when you have a "team...." I'm building a professionally used program just recoding what my father already has done in a different language into Java. We are one man teams :P. I know what they say about each additional person being exponentially harder to complete the project and such. But like they once said "The day of the single coder will be gone..." NAAAAA
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic