JUnit Flashcards
@Test
Denotes that a method is a test method. Unlike JUnit 4’s @Test annotation, this annotation does not declare any attributes, since test extensions in JUnit Jupiter operate based on their own dedicated annotations. Such methods are inherited unless they are overridden.
Denotes that a method is a test method. Unlike JUnit 4’s @Test annotation, this annotation does not declare any attributes, since test extensions in JUnit Jupiter operate based on their own dedicated annotations. Such methods are inherited unless they are overridden.
@Test
@ParameterizedTest
Denotes that a method is a parameterized test. Such methods are inherited unless they are overridden.
Denotes that a method is a parameterized test. Such methods are inherited unless they are overridden.
@ParameterizedTest
@RepeatedTest
Denotes that a method is a test template for a repeated test. Such methods are inherited unless they are overridden.
Denotes that a method is a test template for a repeated test. Such methods are inherited unless they are overridden.
@RepeatedTest
@TestFactory
Denotes that a method is a test factory for dynamic tests. Such methods are inherited unless they are overridden.
Denotes that a method is a test factory for dynamic tests. Such methods are inherited unless they are overridden.
@TestFactory
@TestTemplate
Denotes that a method is a template for test cases designed to be invoked multiple times depending on the number of invocation contexts returned by the registered providers. Such methods are inherited unless they are overridden.
Denotes that a method is a template for test cases designed to be invoked multiple times depending on the number of invocation contexts returned by the registered providers. Such methods are inherited unless they are overridden.
@TestTemplate
@TestClassOrder
Used to configure the test class execution order for @Nested test classes in the annotated test class. Such annotations are inherited.
Used to configure the test class execution order for @Nested test classes in the annotated test class. Such annotations are inherited.
@TestClassOrder
@TestMethodOrder
Used to configure the test method execution order for the annotated test class; similar to JUnit 4’s @FixMethodOrder. Such annotations are inherited.
Used to configure the test method execution order for the annotated test class; similar to JUnit 4’s @FixMethodOrder. Such annotations are inherited.
@TestMethodOrder
@TestInstance
Used to configure the test instance lifecycle for the annotated test class. Such annotations are inherited.
Used to configure the test instance lifecycle for the annotated test class. Such annotations are inherited.
@TestInstance
@DisplayName
Declares a custom display name for the test class or test method. Such annotations are not inherited.
Declares a custom display name for the test class or test method. Such annotations are not inherited.
@DisplayName
@DisplayNameGeneration
Declares a custom display name generator for the test class. Such annotations are inherited.
Declares a custom display name generator for the test class. Such annotations are inherited.
@DisplayNameGeneration
@BeforeEach
Denotes that the annotated method should be executed before each @Test, @RepeatedTest, @ParameterizedTest, or @TestFactory method in the current class; analogous to JUnit 4’s @Before. Such methods are inherited unless they are overridden.
Denotes that the annotated method should be executed before each @Test, @RepeatedTest, @ParameterizedTest, or @TestFactory method in the current class; analogous to JUnit 4’s @Before. Such methods are inherited unless they are overridden.
@BeforeEach
@AfterEach
Denotes that the annotated method should be executed after each @Test, @RepeatedTest, @ParameterizedTest, or @TestFactory method in the current class; analogous to JUnit 4’s @After. Such methods are inherited unless they are overridden.
Denotes that the annotated method should be executed after each @Test, @RepeatedTest, @ParameterizedTest, or @TestFactory method in the current class; analogous to JUnit 4’s @After. Such methods are inherited unless they are overridden.
@AfterEach
@BeforeAll
Denotes that the annotated method should be executed before all @Test, @RepeatedTest, @ParameterizedTest, and @TestFactory methods in the current class; analogous to JUnit 4’s @BeforeClass. Such methods are inherited unless they are overridden and must be static unless the “per-class” test instance lifecycle is used.
Denotes that the annotated method should be executed before all @Test, @RepeatedTest, @ParameterizedTest, and @TestFactory methods in the current class; analogous to JUnit 4’s @BeforeClass. Such methods are inherited unless they are overridden and must be static unless the “per-class” test instance lifecycle is used.
@BeforeAll
@AfterAll
Denotes that the annotated method should be executed after all @Test, @RepeatedTest, @ParameterizedTest, and @TestFactory methods in the current class; analogous to JUnit 4’s @AfterClass. Such methods are inherited unless they are overridden and must be static unless the “per-class” test instance lifecycle is used.
Denotes that the annotated method should be executed after all @Test, @RepeatedTest, @ParameterizedTest, and @TestFactory methods in the current class; analogous to JUnit 4’s @AfterClass. Such methods are inherited unless they are overridden and must be static unless the “per-class” test instance lifecycle is used.
@AfterAll
@Nested
Denotes that the annotated class is a non-static nested test class. On Java 8 through Java 15, @BeforeAll and @AfterAll methods cannot be used directly in a @Nested test class unless the “per-class” test instance lifecycle is used. Beginning with Java 16, @BeforeAll and @AfterAll methods can be declared as static in a @Nested test class with either test instance lifecycle mode. Such annotations are not inherited.
Denotes that the annotated class is a non-static nested test class. On Java 8 through Java 15, @BeforeAll and @AfterAll methods cannot be used directly in a @Nested test class unless the “per-class” test instance lifecycle is used. Beginning with Java 16, @BeforeAll and @AfterAll methods can be declared as static in a @Nested test class with either test instance lifecycle mode. Such annotations are not inherited.
@Nested
@Tag
Used to declare tags for filtering tests, either at the class or method level; analogous to test groups in TestNG or Categories in JUnit 4. Such annotations are inherited at the class level but not at the method level.
Used to declare tags for filtering tests, either at the class or method level; analogous to test groups in TestNG or Categories in JUnit 4. Such annotations are inherited at the class level but not at the method level.
@Tag
@Disabled
Used to disable a test class or test method; analogous to JUnit 4’s @Ignore. Such annotations are not inherited.
Used to disable a test class or test method; analogous to JUnit 4’s @Ignore. Such annotations are not inherited.
@Disabled
@AutoClose
Denotes that the annotated field represents a resource that will be automatically closed after test execution.
Denotes that the annotated field represents a resource that will be automatically closed after test execution.
@AutoClose
@Timeout
Used to fail a test, test factory, test template, or lifecycle method if its execution exceeds a given duration. Such annotations are inherited.
Used to fail a test, test factory, test template, or lifecycle method if its execution exceeds a given duration. Such annotations are inherited.
@Timeout
@TempDir
Used to supply a temporary directory via field injection or parameter injection in a lifecycle method or test method; located in the org.junit.jupiter.api.io package. Such fields are inherited.
Used to supply a temporary directory via field injection or parameter injection in a lifecycle method or test method; located in the org.junit.jupiter.api.io package. Such fields are inherited.
@TempDir
@ExtendWith
Used to register extensions declaratively. Such annotations are inherited.
Used to register extensions declaratively. Such annotations are inherited.
@ExtendWith
@RegisterExtension
Used to register extensions programmatically via fields. Such fields are inherited.