TESTNG ANNOTATION ATTRIBUTES
While writing the test cases in the TestNG, you need to mention the @Test annotation before the test method.
We can also explicitly specify the attributes in a @Test annotation. Test attributes are the test specific, and they are specified at the right next to the @Test annotation.
Some of the common attributes are described below:
- description
- timeOut
- priority
- dependsOnMethods
- enabled
- groups
DESCRIPTION |
It is a string which is attached to the @Test annotation that describes the information about the test.
EXAMPLE:
package testngpackage;
import org.testng.annotations.Test;
public class NewTest {
@Test(description = "This is creat customer")
public void creatcustomer() {
System.out.println("creatcustomer");
}
@Test(description = "This is edit customer")
public void editcustomer() {
System.out.println("editcustomer");
}
@Test(description = "This is modify customer")
public void modifycustomer() {
System.out.println("modifycustomer");
}
@Test(description = "This is delete customer")
public void deletecustomer() {
System.out.println("deletecustomer");
}
}
CONSOLE OUTPUT:
creatcustomer
deletecustomer
edittcustomer
modifycustomer
PASSED: creatcustomer
This is creat customer
PASSED: deletecustomer
This is delete customer
PASSED: editcustomer
This is edit customer
PASSED: modifycustomer
This is modify customer
======================================
Default test
Tests run: 4, Failures: 0, Skips: 0
======================================
======================================
Default suite
Total tests run: 4, Passes: 4, Failures: 0, Skips: 0
======================================
In the above code, we have added the description attribute in every test. The "description" attribute provides information about the test.
TIME-OUT |
If one of the test cases is taking a long time due to which other test cases are failing. To overcome such situation, you need to mark the test case as fail to avoid the failure of other test cases. The timeOut is a time period provided to the test case to completely execute its test case.
EXAMPLE:
package testngpackage;
import org.testng.annotations.Test;
public class NewTest {
@Test (timeOut=20000)
public void creatcustomer() {
System.out.println("creatcustomer");
}
@Test
public void editcustomer() {
System.out.println("editcustomer");
}
@Test
public void modifycustomer() {
System.out.println("modifycustomer");
}
@Test
public void deletecustomer() {
System.out.println("deletecustomer");
}
}
PRIORITY |
DEPENDS ON METHOD |
ENABLED |
GROUPS |