ExpectedExceptions
The list of exceptions that a test method is expected to throw. If no exception or a different than one on this list is thrown, this test will be marked a failure.
Lets create java class
import org.testng.annotations.Test;
publicclass expectexception {
@Test//(expectedExceptions = ArithmeticException.class)
publicvoid divisionWithException() {
System.out.println("thrown expectedExceptions");
inti = 1 / 0;
}
}
TestNG.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none">
<testname="Test1">
<classes>
<classname="expectexception"/>
</classes>
</test><!-- Test -->
</suite><!—Suite -->
Results
If you run test case without expected Exceptions, it will throw an exception.
Comments
Post a Comment