@Test@BeforeEach@BeforeAll@AfterEach@AfterAll@Disabled@Test, @RepeatedTest, @ParameterizedTest, @TestFactory, or @TestTemplate.privatepublicMultiple annotations can be composed to one, which can be used later instead.
Replace @Tag(“fast”) with @Fast
@Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Tag("fast") public @interface Fast { }
Usage:
@Fast @Test void myFastTest() { // ... }
Combine @Tag(“fast”) and @Test to one @FastTest.
@Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Tag("fast") @Test public @interface FastTest { }
Usage:
@FastTest void myFastTest() { // ... }
In direct contrast to failed assertions, failed assumptions do not result in a test failure; rather, a failed assumption results in a test being aborted.
Assumptions are typically used whenever it does not make sense to continue execution of a given test method — for example, if the test depends on something that does not exist in the current runtime environment.
@DisabledOnOs@DisabledOnJre / @DisabledForJreRange@DisabledIfEnvironmentVariable / @DisabledIfEnvironmentVariables@DisabledIfSystemProperty / @DisabledIfSystemProperties@EnabledOnOs@EnabledOnJre / @EnabledForJreRange@EnabledIfEnvironmentVariable / @EnabledIfEnvironmentVariables@EnabledIfSystemProperty / @EnabledIfSystemProperties@TestMethodOrder(OrderAnnotation.class) class OrderedTestsDemo { @Test @Order(1) void nullValues() { // perform assertions against null values } @Test @Order(2) void emptyValues() { // perform assertions against empty values } @Test @Order(3) void validValues() { // perform assertions against valid values } }
@ParameterizedTest@TestMethodOrder - defines test method execution order@TestInstance - ???@DisplayName - declares custom display name for test@DisplayNameGeneration - declares custom display name generator@Nested - ???@Tag - makes possible grouping of tests either on class or on method level@Timeout - used to fail tests, if their execution exceeds a given duration@ExtendWith - ???@RegisterExtension - ???@TempDir - ???