0
编辑:我想写一个失败的测试用例不是积极的。如何测试illegalaccessException?
我正在为我的Java代码编写测试用例。如何为使用反射API的方法编写测试用例。由此产生的代码给我IllegalAccessException。如何在我的JUnit测试用例中创建一个场景,以便我可以测试异常。
public double convertTo(String currency, int amount) {
Class parameters[] = {String.class, int.class};
try {
Method classMethod = clazz.getMethod("convertTo", parameters);
return ((Double) classMethod.invoke(exhangeObject, new Object[]{currency, amount})).doubleValue();
} catch (NoSuchMethodException e) {
throw new CurrencyConverterException();
} catch (InvocationTargetException e) {
throw new CurrencyConverterException();
} catch (IllegalAccessException e) {
System.out.println(e.getClass());
throw new CurrencyConverterException();
}
}
感谢, 斯利拉姆
不,我想要写一个失败的测试情况。不是积极的。 – sriram 2012-03-22 23:33:42
查看我的更新回答。 – Synesso 2012-03-22 23:56:42
第二个。 shouldThrowException – sriram 2012-03-23 00:01:27