标签:io ar sp on bs as new nbsp 如何
当一个被测类中有异常时,如何处理?
如:一个原始的被测类;
public class UserExceptionDemo {
public int age;
public String name;
public void setAge(int age){
if(age<0||age>100){
throw new IllegalArgumentException("ageError!");
}
System.out.println(age);
}
}
junit测试类应该这么写:
public class UserExceptionDemoTest {
@Test(expected = IllegalArgumentException.class)
public void testSetAge() {
UserExceptionDemo user = new UserExceptionDemo();
user.setAge(-1);
}
}
标签:io ar sp on bs as new nbsp 如何
原文地址:http://www.cnblogs.com/sylovezp/p/4123552.html