From 5f7cdf0bf4a485a9434ee0d84a09d975e783eed5 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 16 Mar 2022 18:55:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E6=8A=A5=E5=91=8A=E5=86=85=E5=AE=B9=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9C=AA=E6=89=A7=E8=A1=8C=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 场景报告内容增加未执行统计 --- .../api/dto/ApiScenarioReportDTO.java | 4 + .../ApiScenarioReportStructureService.java | 113 ++++++++++++------ .../api/automation/report/ApiReportDetail.vue | 9 ++ .../automation/report/SysnApiReportDetail.vue | 9 ++ .../report/components/MetricChart.vue | 36 +++++- .../report/components/ScenarioResults.vue | 6 +- .../api/definition/ApiDefinition.vue | 3 - 7 files changed, 133 insertions(+), 47 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/ApiScenarioReportDTO.java b/backend/src/main/java/io/metersphere/api/dto/ApiScenarioReportDTO.java index 65fb188263..18688114a2 100644 --- a/backend/src/main/java/io/metersphere/api/dto/ApiScenarioReportDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/ApiScenarioReportDTO.java @@ -14,16 +14,20 @@ public class ApiScenarioReportDTO { private long total; private long error; private long errorCode; + private long unExecute; private long scenarioTotal; private long scenarioError; private long scenarioSuccess; private long scenarioErrorReport; + private long scenarioUnExecute; private long scenarioStepTotal; private long scenarioStepError; private long scenarioStepSuccess; private long scenarioStepErrorReport; + private long scenarioStepUnExecuteReport; + private long totalAssertions = 0; private long passAssertions = 0; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java index 6066ba10cd..977464ab35 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java @@ -145,14 +145,17 @@ public class ApiScenarioReportStructureService { } } - private void scenarioCalculate(List dtoList, AtomicLong isError, AtomicLong isErrorReport, boolean errorIsFirst) { + private void scenarioCalculate(List dtoList, AtomicLong isError, AtomicLong isErrorReport, AtomicLong isUnExecute, boolean errorIsFirst) { /** * 判断场景步骤的执行状态 * 失败状态的优先级最高,其次是误报 */ for (StepTreeDTO step : dtoList) { if (step.getValue() != null) { - if (StringUtils.isNotEmpty(step.getErrorCode())) { + if (step.getValue() instanceof RequestResultExpandDTO + && StringUtils.equalsIgnoreCase(((RequestResultExpandDTO) step.getValue()).getStatus(), "unexecute")) { + isUnExecute.set(isUnExecute.longValue() + 1); + } else if (StringUtils.isNotEmpty(step.getErrorCode())) { isErrorReport.set(isErrorReport.longValue() + 1); } else if (step.getValue().getError() > 0 || !step.getValue().isSuccess()) { isError.set(isError.longValue() + 1); @@ -160,8 +163,11 @@ public class ApiScenarioReportStructureService { } else if (CollectionUtils.isNotEmpty(step.getChildren())) { AtomicLong isChildrenError = new AtomicLong(); AtomicLong isChildrenErrorReport = new AtomicLong(); - stepChildrenErrorCalculate(step.getChildren(), isChildrenError, isChildrenErrorReport); - if (errorIsFirst) { + AtomicLong isChildrenUnExecute = new AtomicLong(); + stepChildrenErrorCalculate(step.getChildren(), isChildrenError, isChildrenErrorReport, isChildrenUnExecute); + if (isChildrenUnExecute.longValue() > 0) { + isUnExecute.set(isUnExecute.longValue() + 1); + } else if (errorIsFirst) { if (isChildrenError.longValue() > 0) { isError.set(isError.longValue() + 1); } else if (isChildrenErrorReport.longValue() > 0) { @@ -179,15 +185,18 @@ public class ApiScenarioReportStructureService { } } - private void calculate(List dtoList, AtomicLong totalScenario, AtomicLong scenarioError, AtomicLong totalTime, AtomicLong errorReport, boolean isErrorFirst) { + private void calculate(List dtoList, AtomicLong totalScenario, AtomicLong scenarioError, AtomicLong totalTime, AtomicLong errorReport, AtomicLong unExecute, boolean isErrorFirst) { for (StepTreeDTO step : dtoList) { if (StringUtils.equals(step.getType(), "scenario")) { totalScenario.set((totalScenario.longValue() + 1)); // 失败结果数量 AtomicLong error = new AtomicLong(); AtomicLong errorReportCode = new AtomicLong(); - scenarioCalculate(step.getChildren(), error, errorReportCode, isErrorFirst); - if (error.longValue() > 0) { + AtomicLong isUnExecute = new AtomicLong(); + scenarioCalculate(step.getChildren(), error, errorReportCode, isUnExecute, isErrorFirst); + if (isUnExecute.longValue() > 0) { + unExecute.set(unExecute.longValue() + 1); + } else if (error.longValue() > 0) { scenarioError.set((scenarioError.longValue() + 1)); } else if (errorReportCode.longValue() > 0) { errorReport.set((errorReport.longValue() + 1)); @@ -203,15 +212,15 @@ public class ApiScenarioReportStructureService { } } if (CollectionUtils.isNotEmpty(step.getChildren())) { - calculate(step.getChildren(), totalScenario, scenarioError, totalTime, errorReport, isErrorFirst); + calculate(step.getChildren(), totalScenario, scenarioError, totalTime, errorReport, unExecute, isErrorFirst); } } } - private void calculateStep(List dtoList, AtomicLong stepError, AtomicLong stepTotal, AtomicLong stepErrorCode, boolean isErrorFirst) { + private void calculateStep(List dtoList, AtomicLong stepError, AtomicLong stepTotal, AtomicLong stepErrorCode, AtomicLong stepUnExecute, boolean isErrorFirst) { for (StepTreeDTO step : dtoList) { // 失败结果数量 - scenarioCalculate(step.getChildren(), stepError, stepErrorCode, isErrorFirst); + scenarioCalculate(step.getChildren(), stepError, stepErrorCode, stepUnExecute, isErrorFirst); if (CollectionUtils.isNotEmpty(step.getChildren())) { stepTotal.set((stepTotal.longValue() + step.getChildren().size())); } @@ -324,19 +333,9 @@ public class ApiScenarioReportStructureService { reportDTO.setPassAssertions(reportResults.stream().mapToLong(ApiDefinitionExecResultVo::getPassAssertions).sum()); reportDTO.setTotalAssertions(reportResults.stream().mapToLong(ApiDefinitionExecResultVo::getTotalAssertions).sum()); - // 统计场景数据 - AtomicLong totalScenario = new AtomicLong(); - AtomicLong scenarioError = new AtomicLong(); - AtomicLong totalTime = new AtomicLong(); - AtomicLong errorReport = new AtomicLong(); - - calculate(stepList, totalScenario, scenarioError, totalTime, errorReport, true); - reportDTO.setTotalTime(totalTime.longValue()); - reportDTO.setScenarioTotal(totalScenario.longValue()); - reportDTO.setScenarioError(scenarioError.longValue()); - reportDTO.setScenarioErrorReport(errorReport.longValue()); - //统计步骤数据 + reportDTO = this.countReportNum(stepList, reportDTO); reportDTO.setScenarioStepSuccess((reportResults.size() - reportDTO.getError())); + //统计步骤数据 reportDTO.setScenarioStepTotal(reportResults.size()); reportDTO.setScenarioStepError(reportDTO.getError()); reportDTO.setScenarioStepErrorReport(0); @@ -385,44 +384,80 @@ public class ApiScenarioReportStructureService { Map> maps = reportResults.stream().collect(Collectors.groupingBy(ApiScenarioReportResult::getResourceId)); this.reportFormatting(stepList, maps); + reportDTO = this.countReportNum(stepList, reportDTO); + // 统计场景数据 + AtomicLong stepError = new AtomicLong(); + AtomicLong stepTotal = new AtomicLong(); + + reportDTO.setScenarioSuccess((reportDTO.getScenarioTotal() - reportDTO.getScenarioError() - reportDTO.getScenarioUnExecute())); + + //统计步骤数据 + AtomicLong stepErrorCode = new AtomicLong(); + AtomicLong stepUnExecute = new AtomicLong(); + calculateStep(stepList, stepError, stepTotal, stepErrorCode, stepUnExecute, false); + reportDTO.setScenarioStepSuccess((stepTotal.longValue() - stepError.longValue() - stepErrorCode.longValue())); + reportDTO.setScenarioStepTotal(stepTotal.longValue()); + reportDTO.setScenarioStepError(stepError.longValue()); + reportDTO.setScenarioStepErrorReport(stepErrorCode.longValue()); + reportDTO.setScenarioStepUnExecuteReport(stepUnExecute.longValue()); + reportDTO.setConsole(scenarioReportStructure.getConsole()); + reportDTO.setSteps(stepList); + + //统计未执行的请求数量 + AtomicLong allUnExecute = new AtomicLong(); + this.countAllUnexecute(stepList, allUnExecute); + reportDTO.setUnExecute(allUnExecute.longValue()); + } + return reportDTO; + } + + private void countAllUnexecute(List stepList, AtomicLong allUnExecute) { + for (StepTreeDTO step : stepList) { + if (step.getValue() != null) { + if (step.getValue() instanceof RequestResultExpandDTO + && StringUtils.equalsIgnoreCase(((RequestResultExpandDTO) step.getValue()).getStatus(), "unexecute")) { + allUnExecute.set(allUnExecute.longValue() + 1); + } + } + if(CollectionUtils.isNotEmpty(step.getChildren())){ + this.countAllUnexecute(step.getChildren(),allUnExecute); + } + } + } + + private ApiScenarioReportDTO countReportNum(List stepList, ApiScenarioReportDTO reportDTO) { + if (reportDTO != null && CollectionUtils.isNotEmpty(stepList)) { // 统计场景数据 AtomicLong totalScenario = new AtomicLong(); AtomicLong scenarioError = new AtomicLong(); AtomicLong totalTime = new AtomicLong(); AtomicLong errorReport = new AtomicLong(); - AtomicLong stepError = new AtomicLong(); - AtomicLong stepTotal = new AtomicLong(); - - calculate(stepList, totalScenario, scenarioError, totalTime, errorReport, true); + AtomicLong unExecute = new AtomicLong(); + calculate(stepList, totalScenario, scenarioError, totalTime, errorReport, unExecute, true); reportDTO.setTotalTime(totalTime.longValue()); reportDTO.setScenarioTotal(totalScenario.longValue()); reportDTO.setScenarioError(scenarioError.longValue()); reportDTO.setScenarioErrorReport(errorReport.longValue()); - reportDTO.setScenarioSuccess((totalScenario.longValue() - scenarioError.longValue())); - //统计步骤数据 - AtomicLong stepErrorCode = new AtomicLong(); - calculateStep(stepList, stepError, stepTotal, stepErrorCode, false); - reportDTO.setScenarioStepSuccess((stepTotal.longValue() - stepError.longValue() - stepErrorCode.longValue())); - reportDTO.setScenarioStepTotal(stepTotal.longValue()); - reportDTO.setScenarioStepError(stepError.longValue()); - reportDTO.setScenarioStepErrorReport(stepErrorCode.longValue()); - reportDTO.setConsole(scenarioReportStructure.getConsole()); - reportDTO.setSteps(stepList); + reportDTO.setScenarioUnExecute(unExecute.longValue()); } return reportDTO; } - private void stepChildrenErrorCalculate(List dtoList, AtomicLong isError, AtomicLong isErrorReport) { + + private void stepChildrenErrorCalculate(List dtoList, AtomicLong isError, AtomicLong isErrorReport, AtomicLong isUnExecute) { for (StepTreeDTO step : dtoList) { if (step.getValue() != null) { - if (step.getValue().getError() > 0 || !step.getValue().isSuccess()) { + if (step.getValue() instanceof RequestResultExpandDTO + && StringUtils.equalsIgnoreCase(((RequestResultExpandDTO) step.getValue()).getStatus(), "unexecute")) { + isUnExecute.set(isUnExecute.longValue() + 1); + } else if (step.getValue().getError() > 0 || !step.getValue().isSuccess()) { isError.set(isError.longValue() + 1); } if (StringUtils.isNotEmpty(step.getErrorCode())) { isErrorReport.set(isErrorReport.longValue() + 1); } } else if (CollectionUtils.isNotEmpty(step.getChildren())) { - stepChildrenErrorCalculate(step.getChildren(), isError, isErrorReport); + stepChildrenErrorCalculate(step.getChildren(), isError, isErrorReport, isUnExecute); } } } diff --git a/frontend/src/business/components/api/automation/report/ApiReportDetail.vue b/frontend/src/business/components/api/automation/report/ApiReportDetail.vue index d7d0f642ca..ffa8ade416 100644 --- a/frontend/src/business/components/api/automation/report/ApiReportDetail.vue +++ b/frontend/src/business/components/api/automation/report/ApiReportDetail.vue @@ -29,6 +29,13 @@ + + + +