Skip to content

Migrating from TestNG to JUnit Jupiter

Christian Stein edited this page Apr 24, 2024 · 4 revisions

Migrating from TestNG to JUnit Jupiter

  • Test classes should be annotated with @TestInstance(Lifecycle.PER_CLASS) to align with TestNG semantics.
  • @BeforeClass/@AfterClass methods should be annotated with @BeforeAll/@AfterAll.
  • Tests using data providers should be converted to parameterized tests (@ParameterizedTest).
  • The order of the expected and actual arguments to assertion methods such as assertEquals(...) need to be swapped so that the expected result precedes the actual result.
  • Usage of expectThrows(...) should be changed to assertThrows(...).
  • Tests that threw SkipException should make use of the the Assumptions API,

Automated Migration Support

Example Migrations