GeeCON Prague 2014*
The moose likes Testing and the fly likes JUnit Testing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit Testing" Watch "JUnit Testing" New topic
Author

JUnit Testing

wong chang kit
Greenhorn

Joined: May 15, 2012
Posts: 20
Anyone knows what is JUnit Testing and what should write after we create the JUnit testing?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

Please do take some efforts to CarefullyChooseOneForum.
Moving to a more appropriate forum


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

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

Joined: Oct 18, 2011
Posts: 32
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

Joined: Oct 26, 2005
Posts: 40

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.


Tomek Kaczanowski
Book author: Practical Unit Testing with TestNG and Mockito
http://practicalunittesting.com
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30598
    
154

In all fairness, JUnit 4 has parameterized tests built in. The extension makes them more readable/explicit/flexible.


[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
Tomek Kaczanowski
author
Ranch Hand

Joined: Oct 26, 2005
Posts: 40

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JUnit Testing