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?
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:
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.
Book author: Practical Unit Testing with TestNG and Mockito
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.