1 回答

TA貢獻1824條經驗 獲得超6個贊
你的測試有兩個問題:
調用存根必須在實際交互之前配置。所以只需交換這些行:
dataHandler.dataProcessor(json, topic_name, partition);
when(schemaParsor.parseDebeziumSchema(json)).thenReturn(jsonArray); //stub parseDebeziumSchema
Mockito.verify用于驗證與模擬的交互。但是在您的代碼中,您正在驗證對被測對象的方法調用。您看不到此錯誤,因為您的代碼在第 1 點中斷。刪除此行:
verify(dataHandler, Mockito.times(1)).dataProcessor(json, topic_name, partition);
總而言之,您的代碼應如下所示。我還添加了schemaParsor.parseDebeziumSchema(json)僅調用一次的驗證
@Test
public void testdataProcessor() throws JsonParseException, JSONException {
jsonObject.put("field","recipe_name");
jsonObject.put("type","string");
jsonArray.put(jsonObject);
when(schemaParsor.parseDebeziumSchema(json)).thenReturn(jsonArray); //stub parseDebeziumSchema
dataHandler.dataProcessor(json, topic_name, partition);
verify(schemaParsor, times(1)).parseDebeziumSchema(json); //verify that parseDebeziumSchema is called exactly once
}
添加回答
舉報