JUnit 5 vs TestNG
Solution 1
JUnit 5 introduced a lot of new features. Currently Intellij IDEA supports JUnit 5.
Take a look at article about integrating: Using JUnit 5 in IntelliJ IDEA.
There are some useful annotations now, like:
-
@Tag
Used to declare tags for filtering tests, either at the class or method level; analogous to test groups in TestNG or Categories in JUnit 4 -
@DisplayName
Declares a custom display name for the test class or test method
See more: JUnit 5 User Guide
Solution 2
TestNG objective is beyond unit test so it covers wider testing needs like Scenario Tests, Integration Test, Dependency Test, Ordering, Parallel Execution etc, but these feature are not supported in JUnit 5.
The JUnit 5 team have these above items in their road map, but they are extending a unit testing framework to support wider range of testing needs. Lets see how the new subsequent release of Junit 5 is able to address the wider testing need in comparison with TestNG
For Spring based application Junit fits best for doing the Unit and Integration Testing as it the default testing framework and Spring Provides lots of Test API with Mockito.
For general testing and Web Automation (Selenium) - TestNG is the de facto.
Related videos on Youtube
Comments
-
Sergii almost 2 years
We were using JUnit 4, but we had some problems with test grouping. For integration tests we had problems with running order. We had migrated to TestNG in February 2016.
Now we are starting a new independent module for our project and part of our team players wants JUnit 5. I believe it is much better than 4th (there are some new important features, but I see some problems too).
I do not want to use JUnit 5 because of fear of possible problems in our new application, because I have experience with 4th. But I have to be more flexible for the team, so before making a decision I need recommendations from users who have experience with JUnit 5.
-
juherr almost 8 yearsJUnit5 is not yet production ready and only works with java8 minimum.
-
Sergii almost 8 years@JulienHerr, y. It also uses workarounds to run itself in compatible way with junit4.
-
Sergii almost 8 yearsno IDE integration plugins yet for JUnit5...
-
juherr almost 8 yearsIt looks you have no reason to do another migration for the moment ;) fyi, IntelliJ should support junit5 really quickly after the GA.
-
NamshubWriter over 7 years@JulienHerr IDEA already supports JUnit 5. See blog.jetbrains.com/idea/2016/08/using-junit-5-in-intellij-idea
-
Alexei Osipov over 6 yearsDoes
TestNG
give you everything you need? If yes, then stick with it. JUnit 5 still "Work In Progress" and does not support some features of JUnit 4 yet. -
Sergii over 6 yearsYes it does, I think. But not i do not care about test framework, we have started new project and we are using unit tests only, for integration tests we use separate project. It solves our issues
-
-
Phoenix over 6 yearsAlso Eclipse 4.7 Oxygen now support JUnit 5 through the JUnit 5 Support (BETA) for Oxygen 4.7 plugin that can be installed in the marketplace.