Skip to content

Migrating from TestNG to JUnit Jupiter

Sam Brannen edited this page Jun 20, 2024 · 6 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(...) needs 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