*
The moose likes Testing and the fly likes pros & cons of JUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "pros & cons of JUnit " Watch "pros & cons of JUnit " New topic
Author

pros & cons of JUnit

ashok ks
Ranch Hand

Joined: Oct 31, 2003
Posts: 55
What are the pros & cons of JUnit ? (Why should i go for junit test classes instead of writing my own test classes for java )
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
1) JUnit is the de facto standard library for unit testing in Java
2) JUnit is supported out of the box by all major IDEs
3) JUnit has sh*tloads of extensions available for various purposes beyond unit testing plain old Java objects (HttpUnit, JWebUnit, XMLUnit, dbUnit, TagUnit, J2MEUnit, JFCUnit, JUnitPerf, Cactus, SQLUnit to name a few)
4) JUnit has great Ant integration via the <junit> and <junitreport> tasks
Some folks have minor complaints about the restrictions JUnit enforces on your test code, but these issues tend to be really minor annoyances. In fact, most of the time the complaints come up because people try to use plain JUnit for things other than unit testing.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
One more thing...
Originally posted by ashok ks:
Why should i go for junit test classes instead of writing my own test classes for java?
This could be answered with a question: why should I use Eclipse instead of writing my own IDE?
Most of the time, it makes sense to use an existing product instead of building your own. The main reasons for building your own are (1) significant overhead in learning the product, and (2) limitations of existing products. I doubt that the learning curve of JUnit is even close to that of building your own unit test framework, but eventually it's you who needs to make that call.
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
Originally posted by Lasse Koskela:
most of the time the complaints come up because people try to use plain JUnit for things other than unit testing.

Or when you try and work with the JUnit source code. ;-)
JUnit is free, it's simple to work with, it's the standard, as Mr Koskela said. There's little reason not to use it.
-Jeff-


Books: Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
ashok ks
Ranch Hand

Joined: Oct 31, 2003
Posts: 55
Thanks.
Whether JUnit reduces the testing part coding compared with the own java test programs ?
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
It will reduce your code a bit, but the more important thing is getting a consistent framework in place.
-Jeff-
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pros & cons of JUnit
 
Similar Threads
Alternatives to JUnit
Using the Main method as a testing tool
DAO to access to web service?
creating a testing framework using JUnit
java2WSDL and WDL2java