Migration from JUnit 4 to JUnit 5
Our Tech Blog – Current and interesting topics about our work
In our tech blog, we share practical insights into IT, current trends and useful lessons from our daily work. Whether it is innovative software solutions, best practices in digitalization or reports from successful projects – here you will regularly find new articles that keep you up to date. Stop by and discover how we use technology to make businesses more efficient and future-proof.
Migration from JUnit 4 to JUnit 5 in Java and Spring applications
| JUnit 4 Annotation | JUnit 5 Equivalent | Spring specific remarks |
|---|---|---|
| @Before | @BeforeEach | |
| @After | @AfterEach | |
| @BeforeClass | @BeforeAll | |
| @AfterClass | @AfterAll | |
| @Ignore | @Disabled | |
| @Test (expected = Exception.class) | @Test assertThrows(Exception.class, () -> {...}) | |
| @Test (timeout = 100) | @Test assertTimeout(Duration.ofMillis(100), () -> {...}) | |
| @RunWith(SpringJUnit4ClassRunner.class) | @ExtendWith(SpringExtension.class) | Replaced for Spring integration |
| @ContextConfiguration(classes = MyConfig.class) | @SpringJUnitConfig(MyConfig.class) | @SpringJUnitConfig(MyConfig.class) replaces the @ExtendWith(SpringExtension.class) and @ContextConfiguration(classes = MyConfig.class) in JUnit 5, making the test class clearer. |