@Zubin, TestNG gives an option for tracing the Exception handling of code by using Exception test. You can verify whether a code throws the expected exception or not. The expected exception to validate while running the test case is mentioned using the expectedExceptions attribute value along with @Test annotation:
package expectedExceptionPackage;
import org.testng.annotations.Test;
public class TestNGException {
@Test(expectedExceptions = ArithmeticException.class)
public void testException() {
System.out.println("Facebook.com");
int i = 1 / 0;
}
}
Now, the testng.xml file for test case is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="expectedException">
<test name="testngTest">
<classes>
<class name="expectedException.TestNGException" />
</classes>
</test>
</suite>