Russell Bateman
April 2019
last update:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit5.vintage.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.jupiter.version}</version>
<scope>test</scope>
</dependency>
| JUnit 4 | JUnit 5 |
| @Test | @Test |
| @Before | @BeforeEach |
| @After | @AfterEach |
| @BeforeClass | @BeforeAll |
| @AfterClass | @AfterAll |
| @Ignore | @Disabled |
| @Category | @Tag |
@TestMethodOrder( OrderAnnotation.class )
public class MyJUnitTest
{
@Test
@Order( 1 )
public void testSomeCase()
{
...
}
@Test
@Order( 2 )
public void testAnotherCase()
{
...
}
@Test
@Order( 3 )
public void testStillAnotherCase()
{
...
}
}
@ParameterizedTest
@ValueSource( strings = { "Hello", "World" } )
void testWithStringParameter( String argument )
{
System.out.println( "Called with \" + argument + "\"!" );
assertNotNull( argument );
}
testWithStringParameter(String) ✓ ├─ [1] Hello ✓ └─ [2] World ✓