我有这样的方法:的JUnit如何使用@Test(预期= ...)
public String getNum(int x) throws Exception
{
if(x == 0) {
throws new Exception("x cannot be 0");
}
...
}
现在在我的JUnit测试
,我试试这个
@Test(expected=Exception.class)
public void testNum() {
String x = getNum(0);
}
但是Eclipse仍然希望我要么添加一个抛出声明或尝试捕获环绕String x = getNum(0);
。我做错了什么?这个测试应该通过,因为我通过0时期望有例外。
非常感谢。我喜欢小菜 – 2011-05-18 16:14:20
每个人都有时失明。在这里大于2k点,你不能真正成为一个noob。 – 2012-10-26 06:33:43