Yes, like exception handling in java here also in testNG there is a method by which you can handle exceptions
package testNG;
import org.testng.annotations.Test;
public class Test {
@Test
public void testException() {
System.out.println("Check the following");
int i = 1 / 0;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="testNG">
<test name="Test">
<classes>
<class name="TestNGException" />
</classes>
</test>
</suite>
Output:
[TestNG] Running:
Check the following
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
You can see that there is a failed test case. Hope this helps