Best practices for JUnit Jupiter tests.
- Add missing @ParameterizedTest annotation when @ValueSource is used or replace @Test with @ParameterizedTest
- Clean Up Assertions
- Cleanup JUnit imports
- JUnit 4
@Category
to JUnit Jupiter@Tag
- JUnit 4
@RunWith
to JUnit Jupiter@ExtendWith
- JUnit 4
@RunWith(Enclosed.class)
to JUnit Jupiter@Nested
- JUnit 4
@RunWith(Parameterized.class)
to JUnit Jupiter parameterized tests - JUnit 4
Assert
To JUnit JupiterAssertions
- JUnit 4
ExpectedException
To JUnit Jupiter'sassertThrows()
- JUnit 4
MockitoJUnit
to JUnit JupiterMockitoExtension
- JUnit 5 inner test classes should be annotated with
@Nested
- JUnit Jupiter best practices
- JUnit Jupiter migration from JUnit 4.x
- JUnit TestName @Rule to JUnit Jupiter TestInfo
- Make
@TempDir
fields non final - Make lifecycle methods non private
- Migrate JUnit 4
@Test
annotations to JUnit 5 - Migrate JUnit 4
TestCase
to JUnit Jupiter - Migrate JUnit 4 lifecycle annotations to JUnit Jupiter
- Migrate from JUnit 4
@FixedMethodOrder
to JUnit 5@TestMethodOrder
- OkHttp 3.x
MockWebServer
@Rule
To 4.xMockWebServer
- Pragmatists @RunWith(JUnitParamsRunner.class) to JUnit Jupiter Parameterized Tests
- Remove JUnit 4
@RunWith
annotations that do not require an@ExtendsWith
replacement - Remove duplicates uses of @TestTemplate implementations for a single method
- Statically import JUnit Jupiter assertions
- Use
Assertions#assume*(..)
and Hamcrest'sMatcherAssume#assume*(..)
- Use JUnit Jupiter
@Disabled
- Use JUnit Jupiter
@TempDir
- Use JUnit Jupiter
Executable
- Use
MatcherAssert#assertThat(..)
- Use Mockito JUnit Jupiter extension
- Use OkHttp 3 MockWebServer for JUnit 5
- Use Vert.x JUnit 5 Extension
- Use wiremock extension