What is exception test in testng?

0 votes
Jun 19, 2019 in Selenium by Zubin
244 views

1 answer to this question.

0 votes

@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>
answered Jun 19, 2019 by Anvi
• 14,110 points

Related Questions In Selenium

0 votes
2 answers

What is the role of TestNG & JUnit frameworks in Selenium?

TestNG and JUnit are test frameworks . it ...READ MORE

answered Sep 4 in Selenium by Sri
• 2,970 points
887 views
0 votes
2 answers
0 votes
1 answer

What is TestNG and why it is used in selenium?

Hello @User, Talking about TestNG, it is an ...READ MORE

answered Dec 24, 2018 in Selenium by Shuvodip
313 views
0 votes
1 answer

What is the use of grouping in testNG?

Grouping is the method used to separate ...READ MORE

answered Dec 26, 2018 in Selenium by Trisha
264 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
3,785 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,768 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,742 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,111 views
0 votes
1 answer

What is a feature file in Cucumber test and what are its components?

Hey Jagan, Feature file is a file ...READ MORE

answered Aug 27, 2019 in Selenium by Anvi
• 14,110 points
283 views
+1 vote
2 answers