aspose file tools*
The moose likes Testing and the fly likes Unit Testing/JUnit what do we use them for? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Unit Testing/JUnit what do we use them for?" Watch "Unit Testing/JUnit what do we use them for?" New topic
Author

Unit Testing/JUnit what do we use them for?

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

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

Joined: Feb 26, 2001
Posts: 4708
    
    7

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 - [How to Ask Questions] [How to Answer Questions]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4708
    
    7

Here's an interview with Kent Beck, creator of JUnit
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

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

Joined: May 26, 2003
Posts: 30753
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

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

Joined: May 26, 2003
Posts: 30753
    
156

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

Joined: Jun 14, 2011
Posts: 356

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

Joined: May 26, 2003
Posts: 30753
    
156

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

Joined: Jun 14, 2011
Posts: 356

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

Joined: May 26, 2003
Posts: 30753
    
156

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

Joined: Jun 14, 2011
Posts: 356

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
 
subject: Unit Testing/JUnit what do we use them for?