fix(UI 自动化): 场景列表通过率显示为NaN

--bug=1016298 --user=张大海 【UI测试】场景列表通过率显示为NaN https://www.tapd.cn/55049933/s/1234439
This commit is contained in:
zhangdahai112 2022-08-29 15:00:49 +08:00 committed by zhangdahai112
parent d46e5a874d
commit 4db0ceaa59
1 changed files with 10 additions and 3 deletions

View File

@ -505,10 +505,17 @@ public class ApiScenarioReportService {
if (testPlanUiScenario != null) {
report.setScenarioId(testPlanUiScenario.getUiScenarioId());
report.setEndTime(System.currentTimeMillis());
testPlanUiScenario.setLastResult(status);
long successSize = requestResults.stream().filter(requestResult -> StringUtils.equalsIgnoreCase(requestResult.getStatus(), ScenarioStatus.Success.name())).count();
String passRate = new DecimalFormat("0%").format((float) successSize / requestResults.size());
testPlanUiScenario.setPassRate(passRate);
if (StringUtils.equalsAnyIgnoreCase(status, ExecuteResult.UN_EXECUTE.toString())) {
testPlanUiScenario.setLastResult(ScenarioStatus.Fail.name());
} else {
testPlanUiScenario.setLastResult(errorSize > 0 ? ScenarioStatus.Fail.name() : ScenarioStatus.Success.name());
}
if (CollectionUtils.isEmpty(requestResults)) {
testPlanUiScenario.setPassRate("0");
} else {
testPlanUiScenario.setPassRate(new DecimalFormat("0%").format((float) successSize / requestResults.size()));
}
testPlanUiScenario.setReportId(report.getId());
report.setEndTime(System.currentTimeMillis());
testPlanUiScenario.setUpdateTime(System.currentTimeMillis());