fix(接口测试): 修复接口定义用例执行结果状态不显示误报的缺陷

--bug=1032404 --user=王孝刚 【接口测试】case执行结果为误报-api的用例状态为success/失败-未保持一致
https://www.tapd.cn/55049933/s/1434424
This commit is contained in:
wxg0103 2023-11-08 16:17:04 +08:00 committed by wxg0103
parent 9b4ab72d27
commit c44b40c70d
3 changed files with 7 additions and 4 deletions

View File

@ -12,4 +12,5 @@ public class ApiComputeResult {
private String passRate;
private int success;
private int error;
private int fakeError;
}

View File

@ -119,9 +119,9 @@
<select id="selectByIdsAndStatusIsNotTrash" resultType="io.metersphere.api.dto.definition.ApiComputeResult">
SELECT t1.api_definition_id apiDefinitionId,count(t1.id) caseTotal,
SUM(case when t2.status ='SUCCESS' then 1 else 0 end) as SUCCESS ,SUM(case when t2.status in
('ERROR','FAKE_ERROR') then 1 else 0
end) as ERROR,
SUM(case when t2.status ='SUCCESS' then 1 else 0 end) as SUCCESS ,
SUM( CASE WHEN t2.STATUS = 'ERROR' THEN 1 ELSE 0 END ) AS ERROR,
SUM( CASE WHEN t2.STATUS = 'FAKE_ERROR' THEN 1 ELSE 0 END ) AS fakeError,
CONCAT(FORMAT(SUM(IF (t2.`status`='SUCCESS',1,0))/COUNT(t1.id)*100,2),'%') passRate
FROM api_test_case t1
LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id=t2.id

View File

@ -211,10 +211,12 @@ public class ApiDefinitionService {
res.setCaseTotal(String.valueOf(compRes.getCaseTotal()));
res.setCasePassingRate(compRes.getPassRate());
// 状态优先级 未执行未通过通过
if ((compRes.getError() + compRes.getSuccess()) < compRes.getCaseTotal()) {
if ((compRes.getError() + compRes.getSuccess() + compRes.getFakeError()) < compRes.getCaseTotal()) {
res.setCaseStatus(ApiReportStatus.PENDING.name());
} else if (compRes.getError() > 0) {
res.setCaseStatus(ApiReportStatus.ERROR.name());
} else if (compRes.getFakeError() > 0) {
res.setCaseStatus(ApiReportStatus.FAKE_ERROR.name());
} else {
res.setCaseStatus(ApiReportStatus.SUCCESS.name());
}