我正在测试一个用于StringSearch的算法,该算法中有许多IllegalAccessExceptions。
我想测试代码在exceptions...and中是否工作得很好,测试它们也很重要,因为当异常发生时,它们会调用一些函数。
我只想知道如何隐式地生成异常。
我正在尝试使用Java安全管理器,但不知道如何使用它来撤销程序对String类的访问权限。
发布于 2012-12-09 10:02:18
尝试使用Mockito存根方法抛出异常
doThrow(new RuntimeException()).when(mockedList).clear();
//following throws RuntimeException:
mockedList.clear();http://gojko.net/2009/10/23/mockito-in-six-easy-examples/
http://mockito.googlecode.com/svn/tags/1.7/javadoc/org/mockito/internal/stubbing/Stubber.html
https://stackoverflow.com/questions/13783862
复制相似问题