Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
@Test
@DisabledOnEnvironment({"dev", "prod"})
void testFail() {
    fail("this test fails");
}
  • Dependency injection for constructors and methods.

Now it becomes available to define parameters for test constructors and methods and use dependency injection for them. With ParameterResolver class we can resolve parameters in runtime. 

At the time of this writing there are 3 built-in parameter resolvers: TestInfo, RepetitionInfo, TestReporter. Example for one of them:

Code Block
@Test
@DisplayName("Test Get Users")
public void testGetUsersNumberWithInfo(TestInfo testInfo) {
    // test logic.

    logger.info("Running test method:" + testInfo.getTestMethod().get().getName());
}


  • Migration Process.

   Migration from JUnit 4 to 5 is not so difficult, as backward compatibility is available.

...