【发布时间】:2018-10-12 15:55:11
【问题描述】:
任务是在调用table.annotationType().getMethod("name")时引起NoSuchMethodException异常。
我有以下代码
@Mock(answer = RETURNS_DEEP_STUBS)
private Table table;
@Test(expectedExceptions = NoSuchMethodException.class)
public void testGetSupportClassesDatabaseThrowException() throws NoSuchMethodException {
String testPackageName = "com.usc.dbd.util.supporttable";
MockitoAnnotations.initMocks(this);
when(table.annotationType().getMethod("name")).thenThrow(NoSuchMethodException.class);
SupportTables.getSupportClasses(testPackageName);
}
测试失败,NullPointerException 在when... 行。
testCompile("org.mockito:mockito-core:2.7.17")
Table 是来自javax.persistence 的注解
问题可能在于模拟Table 接口。
我正在寻找如何测试这种情况的解决方案。
【问题讨论】:
-
你能分享你完整的依赖集吗?我想尝试找出导致
NullPointerException的原因,但我无法正确缩小依赖关系。
标签: java reflection annotations mockito testng