From 1aa2f94833a348594e21543f2f75972d1598e6b6 Mon Sep 17 00:00:00 2001 From: junhong Date: Sat, 22 Jan 2022 21:50:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=8A=A5=E5=91=8A-?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E8=A1=A8=E5=A4=B4=E5=A2=9E=E5=8A=A0=E7=9A=84?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E8=80=97=E6=97=B6=E5=92=8C=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E7=8E=87=E4=B8=8D=E6=AD=A3=E7=A1=AE=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1009805 --user=周骏弘 【测试跟踪】-报告-报告表头增加的运行耗时和成功率不正确 https://www.tapd.cn/55049933/s/1096595 --- .../mapper/ext/ExtTestPlanReportMapper.xml | 2 +- .../track/service/TestPlanReportService.java | 87 +++++++++++++++++++ .../report/components/TestPlanReportList.vue | 1 - 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportMapper.xml index 3480dfd2c7..790179635b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportMapper.xml @@ -92,7 +92,7 @@ SELECT tpr.id AS id, tpr.`name` AS `name`, tp.`name` AS testPlanName, IF(u.name is null,tpr.creator,u.name)AS creator, tpr.is_new, tpr.test_plan_id, tpr.create_time AS createTime,tpr.trigger_mode AS triggerMode,tpr.status AS status, - tpr.end_time AS endTime, (tpr.end_time - tpr.create_time) AS runTime, tprc.pass_rate AS passRate + tprc.end_time AS endTime, (tprc.end_time - tprc.start_time) AS runTime, tprc.pass_rate AS passRate FROM test_plan tp INNER JOIN test_plan_report tpr on tp.id = tpr.test_plan_id LEFT JOIN user u on tpr.creator = u.id diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index 3dd50e1a24..d1df9d7f92 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -81,6 +81,14 @@ public class TestPlanReportService { private UserService userService; @Resource private ProjectService projectService; + @Resource + ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; + @Resource + private ExtLoadTestReportMapper extLoadTestReportMapper; + @Resource + private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper; + @Resource + private ExtApiScenarioReportMapper extApiScenarioReportMapper; public List list(QueryTestPlanReportRequest request) { List list = new ArrayList<>(); @@ -109,9 +117,88 @@ public class TestPlanReportService { } } list = extTestPlanReportMapper.list(request); + + // 设置测试计划报告成功率 + setTestPlanReportPassRate(list); return list; } + public void setTestPlanReportPassRate(List list){ + for(TestPlanReportDTO testPlanReportDTO : list){ + TestPlanReportContentExample example = new TestPlanReportContentExample(); + example.createCriteria().andTestPlanReportIdEqualTo(testPlanReportDTO.getId()); + List testPlanReportContents = testPlanReportContentMapper.selectByExampleWithBLOBs(example); + + if (CollectionUtils.isNotEmpty(testPlanReportContents)) { + TestPlanReportContentWithBLOBs testPlanReportContent = testPlanReportContents.get(0); + if (testPlanReportContent != null) { + if (this.isDynamicallyGenerateReports(testPlanReportContent)) { + String planId = testPlanReportDTO.getTestPlanId(); + TestPlanSimpleReportDTO report = new TestPlanSimpleReportDTO(); + Map statusResultMap = new HashMap<>(); + + TestPlanExecuteReportDTO testPlanExecuteReportDTO = genTestPlanExecuteReportDTOByTestPlanReportContent(testPlanReportContent); + // 功能用例 + TestPlanUtils.buildStatusResultMap(extTestPlanTestCaseMapper.selectForPlanReport(planId), statusResultMap, report, TestPlanTestCaseStatus.Pass.name()); + + if (testPlanExecuteReportDTO == null) { + // 接口用例 + List planReportApiCaseDTOS = extTestPlanApiCaseMapper.selectForPlanReport(planId); + TestPlanUtils.buildStatusResultMap(planReportApiCaseDTOS, statusResultMap, report, "success"); + // 场景用例 + List planReportScenarioCaseDTOS = extTestPlanScenarioCaseMapper.selectForPlanReport(planId); + TestPlanUtils.buildStatusResultMap(planReportScenarioCaseDTOS, statusResultMap, report, "Success"); + // 性能用例 + List planReportLoadCaseDTOS = extTestPlanLoadCaseMapper.selectForPlanReport(planId); + TestPlanUtils.buildStatusResultMap(planReportLoadCaseDTOS, statusResultMap, report, TestPlanLoadCaseStatus.success.name()); + }else{ + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap())) { + // 接口用例 + List apiReportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap().values()); + List planReportCaseDTOS = extApiDefinitionExecResultMapper.selectForPlanReport(apiReportIds); + TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, "success"); + } + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())) { + // 场景用例 + List reportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap().values()); + List planReportCaseDTOS = extApiScenarioReportMapper.selectForPlanReport(reportIds); + TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, "Success"); + } + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap())) { + // 性能用例 + List reportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap().values()); + List planReportCaseDTOS = extLoadTestReportMapper.selectForPlanReport(reportIds); + // 性能测试的报告状态跟用例的执行状态不一样 + planReportCaseDTOS.forEach(item -> { + if (item.getStatus().equals(PerformanceTestStatus.Completed.name())) { + item.setStatus(TestPlanLoadCaseStatus.success.name()); + } else if (item.getStatus().equals(PerformanceTestStatus.Error.name())) { + item.setStatus(TestPlanLoadCaseStatus.error.name()); + } else { + item.setStatus(TestPlanLoadCaseStatus.run.name()); + } + }); + TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, TestPlanLoadCaseStatus.success.name()); + } + } + // 设置成功率 + if (report.getCaseCount() != null && report.getExecuteCount() != 0) { + report.setExecuteRate(report.getExecuteCount() * 0.1 * 10 / report.getCaseCount()); + } else { + report.setExecuteRate(0.0); + } + if (report.getPassCount() != 0 && report.getCaseCount() != null) { + report.setPassRate(report.getPassCount() * 0.1 * 10 / report.getExecuteCount()); + } else { + report.setPassRate(0.0); + } + testPlanReportDTO.setPassRate(report.getPassRate()); + } + } + } + } + } + public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String projectID, String planId, String userId, String triggerMode) { Map planScenarioIdMap = new LinkedHashMap<>(); Map planTestCaseIdMap = new LinkedHashMap<>(); diff --git a/frontend/src/business/components/track/report/components/TestPlanReportList.vue b/frontend/src/business/components/track/report/components/TestPlanReportList.vue index 684c85b685..08eacc9ab9 100644 --- a/frontend/src/business/components/track/report/components/TestPlanReportList.vue +++ b/frontend/src/business/components/track/report/components/TestPlanReportList.vue @@ -101,7 +101,6 @@ prop="passRate" :field="item" :fields-width="fieldsWidth" - sortable="custom" :label="$t('test_track.report.list.pass_rate')">