Testng生成的測試報告亂碼解決辦法
2017-06-16
1 問題描述
亂碼是程序編碼不統一,比如Java源代碼是utf-8,編譯是gbk,這時會亂碼。
代碼如下:
org.testng.Reporter.log("Response Body: " + StringUtil.RemoveLineBreak(httpResponse.getBody())+"\r\n");
應該顯示:
Response Body: {"responseCode":2000,"responseBody":{"errorMessage":"該筆進件校驗已失敗,請不要再簽章"},"responseMessage":"The contract has been processed"}
實際顯示亂碼:
Response Body: {"responseCode":2000,"responseBody":{"errorMessage":"该笔进件ä¸å˜åœ¨"},"responseMessage":"The contract has been processed"}
2 解決方案
把Eclipse的Java源代碼是設置為utf-8
Window->References->General->Workspace: Text file encoding=UTF-8
eclipse.ini 在最后面加一行參數:
-Duser.language=en_US
