2016-04-29 16 views
-1
public String serialize(Map<String, Object> data) throws IOException { 
    logger.debug("Starting serialisation of json response for thread id [{}] and string [{}]", 
      Thread.currentThread().getId(), data); 
    return (data == null) ? "{}" : new ObjectMapper().writeValueAsString(data); 
} 
+0

創建輸入(地圖)。調用你的方法。檢查它是否返回預期的輸出。這是你可以寫的最簡單的測試。既然你有一個空輸入的特殊情況,添加另一個測試檢查,當輸入爲空時,你會得到預期的輸出。 –

+0

其實我沒有得到任何想法我必須使用這種方法的測試方法 –

+0

然後閱讀:https://github.com/junit-team/junit4/wiki/Getting-started –

回答

0

要測試的方法,一個創建了一個合理的輸入值,然後調用方法,然後檢查產​​值。在你的情況下,輸入值是一個Map<String, Object>和輸出是一些String。所以爲了使這項工作,你會寫這樣的事情:

然後你去。