JUnit Flashcards

1
Q

@Test

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

@Test

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

@ParameterizedTest

A

Denotes that a method is a parameterized test. Such methods are inherited unless they are overridden.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Denotes that a method is a parameterized test. Such methods are inherited unless they are overridden.

A

@ParameterizedTest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

@RepeatedTest

A

Denotes that a method is a test template for a repeated test. Such methods are inherited unless they are overridden.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Denotes that a method is a test template for a repeated test. Such methods are inherited unless they are overridden.

A

@RepeatedTest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

@TestFactory

A

Denotes that a method is a test factory for dynamic tests. Such methods are inherited unless they are overridden.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Denotes that a method is a test factory for dynamic tests. Such methods are inherited unless they are overridden.

A

@TestFactory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

@TestTemplate

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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.

A

@TestTemplate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

@TestClassOrder

A

Used to configure the test class execution order for @Nested test classes in the annotated test class. Such annotations are inherited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Used to configure the test class execution order for @Nested test classes in the annotated test class. Such annotations are inherited.

A

@TestClassOrder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

@TestMethodOrder

A

Used to configure the test method execution order for the annotated test class; similar to JUnit 4’s @FixMethodOrder. Such annotations are inherited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Used to configure the test method execution order for the annotated test class; similar to JUnit 4’s @FixMethodOrder. Such annotations are inherited.

A

@TestMethodOrder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

@TestInstance

A

Used to configure the test instance lifecycle for the annotated test class. Such annotations are inherited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Used to configure the test instance lifecycle for the annotated test class. Such annotations are inherited.

A

@TestInstance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

@DisplayName

A

Declares a custom display name for the test class or test method. Such annotations are not inherited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Declares a custom display name for the test class or test method. Such annotations are not inherited.

A

@DisplayName

19
Q

@DisplayNameGeneration

A

Declares a custom display name generator for the test class. Such annotations are inherited.

20
Q

Declares a custom display name generator for the test class. Such annotations are inherited.

A

@DisplayNameGeneration

21
Q

@BeforeEach

A

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.

22
Q

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.

A

@BeforeEach

23
Q

@AfterEach

A

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.

24
Q

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.

A

@AfterEach

25
Q

@BeforeAll

A

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.

26
Q

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.

A

@BeforeAll

27
Q

@AfterAll

A

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.

28
Q

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.

A

@AfterAll

29
Q

@Nested

A

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.

30
Q

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.

A

@Nested

31
Q

@Tag

A

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.

32
Q

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.

A

@Tag

33
Q

@Disabled

A

Used to disable a test class or test method; analogous to JUnit 4’s @Ignore. Such annotations are not inherited.

34
Q

Used to disable a test class or test method; analogous to JUnit 4’s @Ignore. Such annotations are not inherited.

A

@Disabled

35
Q

@AutoClose

A

Denotes that the annotated field represents a resource that will be automatically closed after test execution.

36
Q

Denotes that the annotated field represents a resource that will be automatically closed after test execution.

A

@AutoClose

37
Q

@Timeout

A

Used to fail a test, test factory, test template, or lifecycle method if its execution exceeds a given duration. Such annotations are inherited.

38
Q

Used to fail a test, test factory, test template, or lifecycle method if its execution exceeds a given duration. Such annotations are inherited.

A

@Timeout

39
Q

@TempDir

A

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.

40
Q

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.

A

@TempDir

41
Q

@ExtendWith

A

Used to register extensions declaratively. Such annotations are inherited.

42
Q

Used to register extensions declaratively. Such annotations are inherited.

A

@ExtendWith

43
Q

@RegisterExtension

A

Used to register extensions programmatically via fields. Such fields are inherited.