Advantages of JUnit 5 – @Tag
- Categorization and Organization is possible by using this @Tag Annotation
- We can be able to perform Selective Execution in the Test Suite
- Filtering in IDEs and Build Tools
- Parallel Execution is achieved by using this annotation.
- Documentation is possible means this Documentation provides information about characteristics, purpose and features.
- Tags can be used in conjunction with conditional test execution.
- Integration with Test Reports.
JUnit 5 – @Tag
The JUnit 5 testing framework provides a lot of features for testing the application. In those features, Tagging is one of them. This tagging is created using @Tag Annotation JUnit 5. JUnit 5 @Tag is used for filtering the test cases based on the given criteria like characteristics, purpose, and features. @Tag is working like a label in the Test Suite. This @Tag Annotation is used in two different levels. The first one is class level and the other one is method level. This means we can apply this Annotation for both test methods and test classes in the test suite of an application.
- @Tag with class level
- @Tag with method level
Syntax for Test class
@Tag("classTag")
public class MyTestClass {
@Test @Tag("methodTag") void testMethod()
{
// Test logic
}
}
Syntax for Test method
public class MyTestClass {
@Test @Tag("methodTag") void testMethod()
{
// Test logic here
}
}
Now we will discuss both of them with examples.
Contact Us