Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pros & cons of JUnit

 
ashok ks
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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-
 
ashok ks
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
Whether JUnit reduces the testing part coding compared with the own java test programs ?
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will reduce your code a bit, but the more important thing is getting a consistent framework in place.
-Jeff-
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic