4
我有以下方法懲戒方法返回null
public ResultScanner getScanner(Scan scan) {
Table table = getTableInstance("Sampletable");
return table.getScanner(scan);
}
爲此,我寫了下面的JUnit測試代碼
Connection mockconnection = PowerMockito.mock(Connection.class);
Table mocktable = PowerMockito.mock(Table.class);
PowerMockito.when(mockconnection.getTable(TableName.valueOf(Mockito.anyString())))
.thenReturn(mocktable);
Scan mockedScan = PowerMockito.mock(Scan.class);
ResultScanner mockrs = PowerMockito.mock(ResultScanner.class);
PowerMockito.when(mocktable.getScanner(mockedScan)).thenReturn(mockrs);
而測試方法
聲明
Table table = getTableInstance("Sampletable");
運行正常,並給出了模擬表對象,但聲明
table.getScanner(scan);
返回null。
請查找表接口的源代碼在下面的鏈接
請指引我在這?
添加含單元測試 –
哪來的'scan'從你的方法來完整的代碼? – isah
對不起,我錯過了參數 – Reddevil