fix(接口测试): 修复报告场景步骤统计错误问题

This commit is contained in:
fit2-zhao 2022-01-10 13:00:04 +08:00 committed by fit2-zhao
parent d22c00a479
commit c3f773ba90
1 changed files with 45 additions and 26 deletions

View File

@ -139,16 +139,11 @@ public class ApiScenarioReportStructureService {
}
}
private void scenarioCalculate(List<StepTreeDTO> dtoList, AtomicLong isError, AtomicLong isErrorReport) {
private void scenarioCalculate(List<StepTreeDTO> dtoList, AtomicLong isErrorReport) {
for (StepTreeDTO step : dtoList) {
if (step.getValue() != null && StringUtils.isNotEmpty(step.getErrorCode())) {
isErrorReport.set(isErrorReport.longValue() + 1);
break;
}else if (step.getValue() != null && step.getValue().getError() > 0) {
isError.set(isError.longValue() + 1);
break;
} else if (CollectionUtils.isNotEmpty(step.getChildren())) {
scenarioCalculate(step.getChildren(), isError,isErrorReport);
}
}
}
@ -160,7 +155,7 @@ public class ApiScenarioReportStructureService {
// 失败结果数量
AtomicLong error = new AtomicLong();
AtomicLong errorCode = new AtomicLong();
scenarioCalculate(step.getChildren(), error,errorCode);
scenarioCalculate(step.getChildren(), errorCode);
if (error.longValue() > 0) {
scenarioError.set((scenarioError.longValue() + 1));
}
@ -183,12 +178,10 @@ public class ApiScenarioReportStructureService {
private void calculateStep(List<StepTreeDTO> dtoList, AtomicLong stepError, AtomicLong stepTotal, AtomicLong stepErrorCode) {
for (StepTreeDTO step : dtoList) {
// 失败结果数量
AtomicLong error = new AtomicLong();
stepErrorCalculate(step.getChildren(), stepError);
AtomicLong errorReport = new AtomicLong();
scenarioCalculate(step.getChildren(), error,errorReport);
if (error.longValue() > 0) {
stepError.set((stepError.longValue() + 1));
}
scenarioCalculate(step.getChildren(), errorReport);
if (errorReport.longValue() > 0) {
stepErrorCode.set((stepErrorCode.longValue() + 1));
}
@ -278,24 +271,50 @@ public class ApiScenarioReportStructureService {
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);
reportDTO.setTotalTime(totalTime.longValue());
reportDTO.setScenarioTotal(totalScenario.longValue());
reportDTO.setScenarioError(scenarioError.longValue());
reportDTO.setScenarioErrorReport(errorReport.longValue());
reportDTO.setScenarioSuccess((totalScenario.longValue() - scenarioError.longValue() -errorReport.longValue()));
//统计步骤数据
AtomicLong stepError = new AtomicLong();
AtomicLong stepErrorCode = new AtomicLong();
AtomicLong stepTotal = new AtomicLong();
calculateStep(stepList, stepError, stepTotal, stepErrorCode);
reportDTO.setScenarioStepSuccess((stepTotal.longValue() - stepError.longValue()));
reportDTO.setScenarioStepTotal(stepTotal.longValue());
reportDTO.setScenarioStepError(stepError.longValue());
reportDTO.setScenarioStepErrorReport(stepErrorCode.longValue());
reportDTO.setScenarioStepSuccess((stepList.size() - stepError.longValue() - stepErrorCode.longValue()));
reportDTO.setConsole(scenarioReportStructure.getConsole());
reportDTO.setSteps(stepList);
}
return reportDTO;
}
private void stepErrorCalculate(List<StepTreeDTO> dtoList, AtomicLong isError) {
for (StepTreeDTO step : dtoList) {
if (step.getValue() != null && step.getValue().getError() > 0) {
isError.set(isError.longValue() + 1);
} else if (CollectionUtils.isNotEmpty(step.getChildren())) {
AtomicLong isChildrenError = new AtomicLong();
stepChildrenErrorCalculate(step.getChildren(), isChildrenError);
if (isChildrenError.longValue() > 0) {
isError.set(isError.longValue() + 1);
}
}
}
}
private void stepChildrenErrorCalculate(List<StepTreeDTO> dtoList, AtomicLong isError) {
for (StepTreeDTO step : dtoList) {
if (step.getValue() != null && step.getValue().getError() > 0) {
isError.set(isError.longValue() + 1);
break;
} else if (CollectionUtils.isNotEmpty(step.getChildren())) {
stepChildrenErrorCalculate(step.getChildren(), isError);
}
}
}
}