Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JUnit Testing

 
wong chang kit
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone knows what is JUnit Testing and what should write after we create the JUnit testing?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do take some efforts to CarefullyChooseOneForum.
Moving to a more appropriate forum
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wong chang kit wrote:Anyone knows what is JUnit Testing and what should write after we create the JUnit testing?

A google for JUnit example gave me http://www.vogella.com/articles/JUnit/article.html and many more.
 
David Sachdev
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have been using Junit 4 for a long time, and have used various mocking frameworks, and default to Mockito these days because of it's ease of use, and limited code that needs to get written in order to create mock objects. I have in the past looked at TestNG, but it has been so long that I can't really recall the benefits that it has. Because Junit has been able to do a good job of what I'm looking for in tests, I haven't explored alternatives in quite a while - but I realize that the downside to that is that I may be putting in more time or effort then I need to in creating tests, checking for code coverage, etc.

As an expert in TestNG, what are the most important benefits you see of using TestNG, and why have you chosen it over Junit?

Thanks
David Sachdev
 
Tomek Kaczanowski
author
Ranch Hand
Posts: 40
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

the main point to remember is, that JUnit was born with unit tests in mind, while TestNG from the very beginning aimed at different types of tests. This makes JUnit good enough for unit tests, but less appropriate for integration and end-to-end tests (which does not mean you can't use it there!).

In my opinion there are numerous benefits you gain when moving from JUnit to TestNG, however I do not think there is any killer feature that would make your coding 50% more effective!

Some time ago I created a presentation which compares JUnit and TestNG, but let me mention few TestNG features here:

* decent parametrized tests,
* some support for concurrency,
* dependencies between tests ,
* test groups,
* very simple to customize its output with custom listeners and reporters,
* other (more advanced) things like factories, methods interceptors or annotations transformers.

Some of the above features really shine outside the realm of unit tests, while some (e.g. parametrized tests or concurrency support) can be also used there. There is no single feature I would point out to, but rather when gathered together they give significantly more power to your hands.

Also, if you look at the development of both projects, you will see a constant improvements and releases of TestNG which contrasts with a rather stagnant JUnit.

P.S. To be honest I have to admit, that some of TestNG features are available as extensions to JUnit, for example parametrized tests.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In all fairness, JUnit 4 has parameterized tests built in. The extension makes them more readable/explicit/flexible.
 
Tomek Kaczanowski
author
Ranch Hand
Posts: 40
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

true, JUnit 4 has parametrized tests but they are awkward to use (constructor-based), and from my experience they are rarely used. I pointed to JUnit Params, as it offers parametrized tests done right.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic