JUnit Annotations

JUnit6 Logo

JUnit @AutoClose Annotation with Examples

JUnit @AutoClose automatically close resources that implement AutoCloseable after each test, without requiring explicit cleanup code. If any exception occurs during closing the resource, the exception is suppressed.

JUnit 5 @Disabled Test Example

JUnit @Disabled annotation can be used to disable the test methods from test suite. This annotation can be applied over a test class as well as over individual test methods.

JUnit 5 @Tag Example: Label, Filter and Run Tests

JUnit 5 @Tag can be used to filter testcases from test plans. It can help in create multiple different test plans for different environments, different use-cases or any specific requirement. You can execute set of tests by including only those tagged tests in test plan OR by excluding other tests from test plan.

JUnit 5 @RepeatedTest

JUnit 5 @RepeatedTest annotation enable to write repeatable test templates which could be run multiple times. The frequency can be configured as parameter to @RepeatedTest annotation.

JUnit 5 @AfterAll

JUnit 5 @AfterAll annotation is replacement of @AfterClass annotation in JUnit 4. The annotated method should be executed after all tests in test class.

JUnit 5 @AfterEach

JUnit 5 @AfterEach annotation is replacement of @After annotation in JUnit 4.The annotated method should be executed after each @Test method in test class.

JUnit 5 @BeforeEach

JUnit 5 @BeforeEach annotation is replacement of @Before annotation in JUnit 4. Annotated method should be executed before each @Test method in test class.

JUnit 5 @BeforeAll

JUnit 5 @BeforeAll annotation is replacement of @BeforeClass and is used to signal that annotated method should be executed before all tests in test class.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.