TestNG Test Annotation
The most important annotation of TestNG is Test annotation. This annotation marks a method or class as TestNG test. It you apply at class level then it will mark all the public methods present inside the class as test methods. It had lot of attributes which you can use along with the Test annotation, which will enable you to use the different features provided by the TestNG unit test framework.
Below are the list of attributes which we can use along with the Test annotation:
[table id=3 /]
Will learn about all these attributes in the coming blogs.
We already seen sample tests using Test annotation on methods, will see how can we use Test annotation at class level in the below example:
[java]
import org.testng.annotations.Test;
@Test
public class ClassLevelTestAnnotation
{
public void firstTest()
{
System.out.println("In First Test");
}
public void secondTest()
{
System.out.println("In Second Test");
}
public void thirdTest()
{
System.out.println("In Third Test");
}
}
[/java]
Run the above code using below xml configuration file:
[xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<classes>
<class name="ClassLevelTestAnnotation"></class>
</classes>
</test>
</suite>
[/xml]
Output for the above code is:
We can observe from the above is, we did not added the Test annotation to any of the methods in the class. Instead, we have put the Test annotation at the class level, then this will be applicable to all the public methods in the class.











