Saturday 19 June 2021

Junit 5: Jupiter core annotations

org.junit.jupiter.api package contains core annotations. Below table summarizes the core annotations of junit 5 jupiter.

 

Annotation

Description

AfterAll

@AfterAll is used to signal that the annotated method should be executed after all tests in the current test class.

AfterEach

@AfterEach is used to signal that the annotated method should be executed after each @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, and @TestTemplate method in the current test class.

BeforeAll

@BeforeAll is used to signal that the annotated method should be executed before all tests in the current test class.

BeforeEach

@BeforeEach is used to signal that the annotated method should be executed before each @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, and @TestTemplate method in the current test class.

Disabled

@Disabled is used to signal that the annotated test class or test method is currently disabled and should not be executed.

DisplayName

@DisplayName is used to declare a custom display name for the annotated test class or test method.

DisplayNameGeneration

@DisplayNameGeneration is used to declare a custom display name generator for the annotated test class.

Nested

@Nested is used to signal that the annotated class is a nested, non-static test class (i.e., an inner class) that can share setup and state with an instance of its enclosing class.

Order

@Order is an annotation that is used to configure the order in which the annotated element (i.e., field or method) should be evaluated or executed relative to other elements of the same category.

RepeatedTest

@RepeatedTest is used to signal that the annotated method is a test template method that should be repeated a specified number of times with a configurable display name.

Tag

@Tag is a repeatable annotation that is used to declare a tag for the annotated test class or test method.

Tags

@Tags is a container for one or more @Tag declarations.

Test

@Test is used to signal that the annotated method is a test method.

TestFactory

@TestFactory is used to signal that the annotated method is a test factory method.

TestInstance

@TestInstance is a type-level annotation that is used to configure the lifecycle of test instances for the annotated test class or test interface.

TestMethodOrder

@TestMethodOrder is a type-level annotation that is used to configure a MethodOrderer for the test methods of the annotated test class or test interface.

TestTemplate

@TestTemplate is used to signal that the annotated method is a test template method.

Timeout

@Timeout is used to define a timeout for a method or all testable methods within one class and its @Nested classes.


You can download complete working applications from this link.

https://github.com/harikrishna553/junit5/tree/master/junit5-examples

Previous                                                    Next                                                    Home

No comments:

Post a Comment