refactor(接口测试): 场景和用例未执行、误报状态报告优化

--bug=1013743 --user=宋天阳
【接口测试】场景和用例未执行、误报状态报告优化
https://www.tapd.cn/55049933/s/1173289
This commit is contained in:
song-tianyang 2022-06-06 15:48:33 +08:00 committed by f2c-ci-robot[bot]
parent ca778d44c9
commit acc93fe825
4 changed files with 52 additions and 33 deletions

View File

@ -12,6 +12,7 @@ import io.metersphere.api.dto.datacount.ApiDataCountResult;
import io.metersphere.api.jmeter.FixedCapacityUtils;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
import io.metersphere.base.mapper.ext.ExtApiScenarioReportResultMapper;
import io.metersphere.commons.constants.*;
@ -83,6 +84,8 @@ public class ApiScenarioReportService {
@Resource
private ApiDefinitionExecResultMapper definitionExecResultMapper;
@Resource
private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper;
@Resource
private UiReportServiceProxy uiReportServiceProxy;
@Resource
private ExtApiScenarioReportResultMapper extApiScenarioReportResultMapper;
@ -352,17 +355,50 @@ public class ApiScenarioReportService {
return report;
}
private String getIntegrationReportStatus(List<String> reportStatus) {
boolean hasError = false, hasErrorReport = false, hasUnExecute = false, hasOtherStatus = false, hasStop = false;
if (CollectionUtils.isEmpty(reportStatus)) {
//查不到任何结果按照未执行来处理
hasUnExecute = true;
}else {
for (String status : reportStatus) {
if (StringUtils.equalsIgnoreCase(status, ExecuteResult.Error.name())) {
hasError = true;
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.errorReportResult.name())) {
hasErrorReport = true;
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.STOP.name())) {
hasStop = true;
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.unexecute.name())) {
hasUnExecute = true;
} else {
hasOtherStatus = true;
}
}
if (hasError || hasErrorReport || hasOtherStatus) {
//根据状态优先级判定只要存在失败/误报/其他待定状态 的数据 则未执行和停止都为false 优先级最低
hasUnExecute = false;
hasStop = false;
}
}
return hasError ? ScenarioStatus.Error.name() :
hasErrorReport ? ExecuteResult.errorReportResult.name() :
hasStop ? ExecuteResult.STOP.name() :
hasUnExecute ? ExecuteResult.unexecute.name() : ScenarioStatus.Success.name();
}
public void margeReport(String reportId, String runMode, String console) {
// 更新场景状态
List<String> statusList = null;
if (StringUtils.equalsIgnoreCase(runMode, ApiRunMode.DEFINITION.name())) {
ApiDefinitionExecResultWithBLOBs result = definitionExecResultMapper.selectByPrimaryKey(reportId);
if (!StringUtils.equalsAnyIgnoreCase(result.getStatus(), APITestStatus.Rerunning.name())) {
result.setEndTime(System.currentTimeMillis());
}
ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample();
execResultExample.createCriteria().andIntegratedReportIdEqualTo(reportId).andStatusEqualTo("Error");
long size = definitionExecResultMapper.countByExample(execResultExample);
result.setStatus(size > 0 ? ScenarioStatus.Error.name() : ScenarioStatus.Success.name());
statusList = extApiDefinitionExecResultMapper.selectDistinctStatusByReportId(reportId);
result.setStatus(this.getIntegrationReportStatus(statusList));
result.setEndTime(System.currentTimeMillis());
definitionExecResultMapper.updateByPrimaryKeySelective(result);
} else {
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId);
@ -370,30 +406,9 @@ public class ApiScenarioReportService {
if (!StringUtils.equalsAnyIgnoreCase(report.getStatus(), APITestStatus.Rerunning.name())) {
report.setEndTime(System.currentTimeMillis());
}
List<String> statusList = extApiScenarioReportResultMapper.selectDistinctStatusByReportId(reportId);
boolean hasError = false, hasErrorReport = false, hasUnExecute = false, hasOtherStatus = false;
for (String status : statusList) {
if (StringUtils.equalsIgnoreCase(status, ExecuteResult.Error.name())) {
hasError = true;
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.errorReportResult.name())) {
hasErrorReport = true;
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.unexecute.name())) {
hasUnExecute = true;
} else {
hasOtherStatus = true;
}
}
if (hasUnExecute && (hasError || hasErrorReport || hasOtherStatus)) {
//只有全部状态都是未执行时集合报告的状态才可以是未执行
hasUnExecute = false;
}else if(CollectionUtils.isEmpty(statusList)){
//查不到任何结果也按照未执行来处理
hasUnExecute = true;
}
report.setStatus(hasError ? ScenarioStatus.Error.name() :
hasErrorReport ? ExecuteResult.errorReportResult.name() :
hasUnExecute ? ExecuteResult.unexecute.name() : ScenarioStatus.Success.name());
statusList = extApiScenarioReportResultMapper.selectDistinctStatusByReportId(reportId);
report.setStatus(this.getIntegrationReportStatus(statusList));
report.setEndTime(System.currentTimeMillis());
// 更新报告
apiScenarioReportMapper.updateByPrimaryKey(report);
}
@ -889,7 +904,7 @@ public class ApiScenarioReportService {
} else if (errorReportResultSize > 0) {
status = ExecuteResult.errorReportResult.name();
} else {
status = requestResults.isEmpty() ? ScenarioStatus.Error.name() : ScenarioStatus.Success.name();
status = requestResults.isEmpty() ? ExecuteResult.unexecute.name() : ScenarioStatus.Success.name();
}
if (dto != null && dto.getArbitraryData() != null && dto.getArbitraryData().containsKey("TIMEOUT") && (Boolean) dto.getArbitraryData().get("TIMEOUT")) {

View File

@ -47,5 +47,5 @@ public interface ExtApiDefinitionExecResultMapper {
List<ApiDefinitionExecResult> findByProjectIds(@Param("request") TaskCenterRequest request);
List<String> selectDistinctStatusByReportId(String reportId);
}

View File

@ -32,6 +32,10 @@
WHERE testCase.project_id = #{projectId})
</select>
<select id="selectDistinctStatusByReportId" resultType="java.lang.String">
SELECT DISTINCT status FROM api_definition_exec_result WHERE integrated_report_id = #{0}
</select>
<select id="findFaliureCaseInfoByProjectIDAndExecuteTimeAndLimitNumber" resultType="io.metersphere.api.dto.datacount.ExecutedCaseInfoResult">
SELECT * FROM (
-- api_test_case 只查找测试计划执行的结果

View File

@ -5,14 +5,14 @@ public enum ExecuteResult {
errorReportResult,
//接口执行状态(兼容旧数据)
success,error,
success, error, STOP,
//未执行状态
unexecute,
//场景执行状态(兼容旧数据)
Success,Error,
Success, Error,
//测试计划执行状态(兼容旧数据)
PREPARE,RUNNING,SUCCESS,FAILD
PREPARE, RUNNING, SUCCESS, FAILD
}