Written by
		
			Oğuzhan İNAN
		
		
			
on
	on
TestNG Exception Testi Nedir
TestNG yazılan kodun istisna (exception) durumlarını kontrol etme imkanı verir.
Yazılan kodun istenen istisnayı fırlatıp fırlatmadığını kontrol edebiliriz.
@Test açıklamasının expectedExceptions parametresine verilecek istisnalar testte fırlatılmazsa test başarısız olur.
public class ExceptionTest {
    @Test(expectedExceptions = {ArithmeticException.class})
    public void exceptionTest() {
        int a = 1 / 0;
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="suite">
   <test name="exceptionTest">
      <classes>
         <class name="com.testng.app.ExceptionTest" />
      </classes>
   </test>
</suite>	
Yukarıdaki durumda test başarılı olur. 1 / 5 yaparsak eğer bir hata olmayacağı için test başarısız olur.
public class ExceptionTest {
    @Test(expectedExceptions = {ArithmeticException.class})
    public void exceptionTest() {
        int a = 1 / 5;
    }
}