It’s used to test the exception throw by the method.

import org.testng.annotations.*;
 
/**
 * TestNG Expected Exception Test
 * @author mkyong
 *
 */
public class TestNGTest2 {
 
	@Test(expectedExceptions = ArithmeticException.class)  
	public void divisionWithException() {  
	  int i = 1/0;
	}  
 
}

In above example, the divisionWithException() method will throw an ArithmeticException Exception, since this is an expected exception, so the unit test will pass.

Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~