From d4ff01161af8dc2f8451f4a79fe7ab104577263e Mon Sep 17 00:00:00 2001 From: zhangdahai112 Date: Mon, 29 Aug 2022 15:00:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(UI=20=E8=87=AA=E5=8A=A8=E5=8C=96):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=88=97=E8=A1=A8=E9=80=9A=E8=BF=87=E7=8E=87?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=BANaN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016298 --user=张大海 【UI测试】场景列表通过率显示为NaN https://www.tapd.cn/55049933/s/1234439 --- .../api/service/ApiScenarioReportService.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 3a9a8c15c2..5528e86074 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -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());