Steps

@Before → @BeforeEach @After → @AfterEach @BeforeClass → @BeforeAll @AfterClass → @AfterAll @org.junit.Test → @org.junit.jupiter.api.Test import static org.junit.Assert.assertTrue → import static org.junit.jupiter.api.Assertions.assertTrue (same for the other assertions) If using Mockito, @RunWith(MockitoJUnitRunner.class) → @ExtendWith(MockitoExtension.class)

Example

RED: Removed

GREEN: Added

import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue import org.junit.Before; import org.junit.jupiter.api.BeforeEach; import org.junit.Test; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension; @RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class) public class FooTest { @Mock private Bar barMock; @Before @BeforeEach public void setUp() throws Exception { } @Test public void testFoo() { /* ... */ } }

Dependencies

Here are the dependencies for Gradle:

You can easily adapt them for Maven, but don’t forget to set <scope>test</scope>.

testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.3.1' testImplementation 'org.mockito:mockito-core:2.28.2' testImplementation 'org.mockito:mockito-junit-jupiter:2.28.2' // For MockitoExtension

Further reading

Check out the JUnit 5 User Guide to learn about the new features. There are some cool ones, like parameterized tests and repeated tests.