JUnit 5 vs TestNG

12,934

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.

Share:
12,934

Related videos on Youtube

Sergii
Author by

Sergii

The main expertise is in Java

Updated on June 04, 2022

Comments

  • Sergii
    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
      juherr almost 8 years
      JUnit5 is not yet production ready and only works with java8 minimum.
    • Sergii
      Sergii almost 8 years
      @JulienHerr, y. It also uses workarounds to run itself in compatible way with junit4.
    • Sergii
      Sergii almost 8 years
      no IDE integration plugins yet for JUnit5...
    • juherr
      juherr almost 8 years
      It looks you have no reason to do another migration for the moment ;) fyi, IntelliJ should support junit5 really quickly after the GA.
    • NamshubWriter
      NamshubWriter over 7 years
      @JulienHerr IDEA already supports JUnit 5. See blog.jetbrains.com/idea/2016/08/using-junit-5-in-intellij-id‌​ea
    • Alexei Osipov
      Alexei Osipov over 6 years
      Does 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
      Sergii over 6 years
      Yes 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
    Phoenix over 6 years
    Also 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.