预计测试会出现异常,可以使用@Test(expectedExceptions=)来验证是否有异常抛出。
import org.testng.Reporter;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestException {
@Test(description="测试异常",dataProvider="data", expectedExceptions=ArithmeticException.class)
public void TestDataOut(int a,int b) {
int result=a+b;
System.out.println("result:"+result);
Reporter.log("测试结果:"+result);
}
@DataProvider(name="data")
public Object[][]dataprovide(){
return new Object[][] {
new Object[] {111111,1111111111},
new Object[] {4,2147483647},
};
}
}
测试结果
Maven Surefire Plugin参看http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html