Junit 4
- Monolithic : Everything is bundled into a single jar junit4.jar
Junit 5:
-
Platform
- Internal common library/utilities of JUnit - Public API for test engines - Public API for configuring and launching test plans. - Runner and annotations for configuring and executing tests.
-
Jupiter
- New junit annotations and TestEngine implementation to run tests written with these annotations. - Migration support from JUnit 4 to JUnit Jupiter
-
Vintage
- support running JUnit 3 and JUnit 4 written tests on the JUnit 5 platform.
Features | JUnit 5 | JUnit 4 |
---|---|---|
Declares a test method | @Test | @Test |
Denotes that the annotated method will be executed before all test methods in the current class | @BeforeAll | @ BeforeClass |
Denotes that the annotated method will be executed after all test methods in the current class | @AfterAll | @AfterClass |
Denotes that the annotated method will be executed before each test method | @BeforeEach | @Before |
Denotes that the annotated method will be executed after each test method | @AfterEach | @After |
Disable a test method or a test class | @Disable | @Ignore |
Denotes a method is a test factory for dynamic tests in JUnit 5 | @TestFactory | N/A |
Denotes that the annotated class is a nested, non-static test class | @Nested | N/A |
Declare tags for filtering tests | @Tag | @Category |
Register custom extensions in JUnit 5 | @ExtendWith | N/A |
JUnit 5 | JUnit 4 |
---|---|
fail | fail |
assertTrue | assertTrue |
N/A | assertThat |
assertSame | assertSame |
assertNull | assertNull |
assertNotSame | assertNotSame |
assertNotEquals | assertNotEquals |
assertNotNull | assertNotNull |
assertFalse | assertFalse |
assertEquals | assertEquals |
assertArrayEquals | assertArrayEquals |
assertAll | N/A |
assertThrows | N/A |
assertTimeout | N/A |
assertTimeoutPreemptively | N/A |
JUnit 5 | JUnit 4 |
---|---|
assumeFalse | assumeFalse |
assumeNoException | |
assumeNotNull | |
assumeThat | assumeThat |
assumeTrue | assumeTrue |
Junit 5 Example-1 Junit 5 Example-2 Junit 5 Example-3
Junit 5 Example-1 Junit 5 Example-2
Junit 4 Example-1 Junit 4 Example-2 Junit 4 Example-3
Junit 4 Example-1 Junit 4 Example-2
See @EnableRuleMigrationSupport