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