Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

JUnit Testing

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone knows what is JUnit Testing and what should write after we create the JUnit testing?
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do take some efforts to CarefullyChooseOneForum.
Moving to a more appropriate forum
 
Maneesh Godbole
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 75
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 40
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 40552
825
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 40
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic