@Test
annotation can be applied to any class or method. This annotation marks a class or a method as part of the test.
@Test
at method level - mark annotated method as test method@Test
at class level
@Test
annotation is to make all the public methods of the class to become test methods even if they are not annotated.@Test
annotation can also be repeated on a method if you want to add certain attributes.Example of @Test
at method level:
import org.testng.annotations.Test;
public class TestClass1 {
public void notTestMethod() {
}
@Test
public void testMethod() {
}
}
Example of @Test
at class level:
import org.testng.annotations.Test;
@Test
public class TestClass2 {
public void testMethod1() {
}
@Test
public void testMethod2() {
}
}