JUnit annotations are specialized syntactic meta-data used in Java to improve readability and code structure – they can be applied to variables, classes, methods, packages, and parameters.
@Test
@Test(timeout = 50)
@ParametrizedTest
@RepeatedTest
@TestInstance
@Nested
@BeforeEach
@AfterEach
@BeforeAll
@AfterAll
@BeforeClass
@AfterClass
@Disabled
The code below suggests how different annotations can be used.
class HelloWorld { @AfterTest public static void a_t( String args[] ) { System.out.println( "Run this after running Test!!" ); } @AfterClass public static void a_c( String args[] ) { System.out.println( "Run this after running all Tests in a class!!" ); } @Test public static void _t( String args[] ) { System.out.println( "Test method" ); } @BeforeTest public static void b_t( String args[] ) { System.out.println( "Run this before running Test!!" ); } @BeforeClass public static void b_c( String args[] ) { System.out.println( "Run this before running all Tests in a class!!" ); } }
Most of these annotations can be found in the
org.junit.jupiter.api
package in thejunit-jupiter-api
module.
RELATED TAGS
View all Courses