fix(接口测试): 修改接口测试首页执行相关统计的公式

修改接口测试首页执行相关统计的公式
This commit is contained in:
song-tianyang 2022-11-12 14:28:03 +08:00 committed by 建国
parent d3eb043730
commit cc1a601281
6 changed files with 34 additions and 33 deletions

View File

@ -31,6 +31,8 @@ public class ApiDataCountDTO {
//本周执行次数
private long executedTimesInWeek = 0;
//历史执行总次数
private long executedTimes = 0;
//执行的数据数
private long executedCount = 0;
private long notExecutedCount = 0;
private long passCount = 0;
@ -119,6 +121,7 @@ public class ApiDataCountDTO {
this.passCount += countResult.getCountNumber();
}
}
this.executedCount = this.unPassCount + this.fakeErrorCount + this.passCount;
}
/**
@ -127,7 +130,7 @@ public class ApiDataCountDTO {
* @return
*/
public long getExecutedData() {
return this.unPassCount + this.fakeErrorCount + this.passCount;
return this.executedCount;
}
public void countApiCaseRunResult(List<ExecuteResultCountDTO> executeResultCountDTOList) {
@ -145,6 +148,7 @@ public class ApiDataCountDTO {
this.unPassCount += execResult.getCount();
}
}
this.executedCount = this.unPassCount + this.fakeErrorCount + this.passCount;
}
public void countScheduleExecute(List<ApiDataCountResult> allExecuteResult) {
@ -153,7 +157,7 @@ public class ApiDataCountDTO {
this.passCount += countResult.getCountNumber();
} else if (StringUtils.equalsAnyIgnoreCase(countResult.getGroupField(), ApiReportStatus.ERROR.name())) {
this.unPassCount += countResult.getCountNumber();
} else if (StringUtils.equalsAnyIgnoreCase(countResult.getGroupField(), ApiReportStatus.FAKE_ERROR.name())) {
} else if (StringUtils.equalsAnyIgnoreCase(countResult.getGroupField(), ApiReportStatus.FAKE_ERROR.name(), "errorReportResult")) {
this.fakeErrorCount += countResult.getCountNumber();
}
}

View File

@ -1012,16 +1012,13 @@
<select id="selectExecuteResultByProjectId"
resultType="io.metersphere.api.dto.datacount.response.ExecuteResultCountDTO">
SELECT t3.status AS execResult, count(t1.id) AS `count`
FROM api_test_case t1
LEFT JOIN api_definition_exec_result t3 ON t1.last_result_id = t3.id
WHERE t1.project_id = #{0}
AND (t1.`status` IS NULL OR t1.`status` != 'Trash')
AND t1.api_definition_id IN (SELECT id
FROM api_definition
WHERE project_id = #{0}
AND latest = 1)
GROUP BY t3.`status`
SELECT `status` AS execResult,count(id) AS count
FROM api_test_case
WHERE `status` != 'Trash' AND api_definition_id IN
(SELECT id FROM api_definition
WHERE project_id = #{0} AND latest IS TRUE)
GROUP BY `status`
</select>
<select id="caseList" resultType="io.metersphere.base.domain.ApiTestCaseWithBLOBs">
SELECT

View File

@ -12,6 +12,7 @@ import io.metersphere.api.dto.export.ScenarioToPerformanceInfoDTO;
import io.metersphere.base.domain.ApiDefinition;
import io.metersphere.base.domain.Schedule;
import io.metersphere.commons.constants.ReportTriggerMode;
import io.metersphere.commons.enums.ExecutionExecuteTypeEnum;
import io.metersphere.commons.utils.DataFormattingUtil;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.service.BaseScheduleService;
@ -97,8 +98,8 @@ public class ApiHomeController {
apiCountResult.setCreatedInWeek(dateCountByCreateInThisWeek);
long executedInThisWeekCountNumber = apiDefinitionExecResultService.countByTestCaseIDInProjectAndExecutedInThisWeek(projectId);
apiCountResult.setExecutedTimesInWeek(executedInThisWeekCountNumber);
long executedCount = apiTestCaseService.countExecutedTimesByProjectId(projectId);
apiCountResult.setExecutedCount(executedCount);
long executedCount = apiTestCaseService.countExecutedTimesByProjectId(projectId, ExecutionExecuteTypeEnum.BASIC.name());
apiCountResult.setExecutedTimes(executedCount);
//未覆盖 已覆盖 统计当前接口下是否含有案例
List<ApiDataCountResult> countResultByApiCoverageList = apiDefinitionService.countApiCoverageByProjectID(projectId);
apiCountResult.countApiCoverage(countResultByApiCoverageList);
@ -113,7 +114,7 @@ public class ApiHomeController {
apiCountResult.countApiCaseRunResult(apiCaseExecResultList);
if (apiCountResult.getExecutedCount() > 0) {
//通过率
float coveredRateNumber = (float) apiCountResult.getPassCount() * 100 / apiCountResult.getExecutedCount();
float coveredRateNumber = (float) apiCountResult.getPassCount() * 100 / apiCountResult.getTotal();
DecimalFormat coveredRateFormat = new DecimalFormat("0.0");
apiCountResult.setPassRate(coveredRateFormat.format(coveredRateNumber) + "%");
@ -138,15 +139,15 @@ public class ApiHomeController {
long executedInThisWeekCountNumber = apiScenarioReportService.countByProjectIdAndCreateInThisWeek(projectId);
apiCountResult.setExecutedTimesInWeek(executedInThisWeekCountNumber);
//所有执行次数
long executedCount = apiAutomationService.countExecuteTimesByProjectID(projectId, null);
apiCountResult.setExecutedCount(executedCount);
long executedTimes = apiAutomationService.countExecuteTimesByProjectID(projectId, null);
apiCountResult.setExecutedTimes(executedTimes);
//未执行未通过已通过
List<ApiDataCountResult> countResultByRunResult = apiAutomationService.countRunResultByProjectID(projectId);
apiCountResult.countScenarioRunResult(countResultByRunResult);
DecimalFormat df = new DecimalFormat("0.0");
if (executedCount != 0) {
if (apiCountResult.getExecutedData() != 0) {
//通过率
float coveredRateNumber = (float) apiCountResult.getPassCount() * 100 / executedCount;
float coveredRateNumber = (float) apiCountResult.getPassCount() * 100 / apiCountResult.getTotal();
apiCountResult.setPassRate(df.format(coveredRateNumber) + "%");
//执行率
float executedRateNumber = (float) apiCountResult.getExecutedData() * 100 / apiCountResult.getTotal();
@ -180,16 +181,15 @@ public class ApiHomeController {
apiCountResult.setCreatedInWeek(taskCountInThisWeek);
long executedInThisWeekCountNumber = apiScenarioReportService.countByProjectIdAndCreateAndByScheduleInThisWeek(projectId);
apiCountResult.setExecutedTimesInWeek(executedInThisWeekCountNumber);
long executedCount = apiAutomationService.countExecuteTimesByProjectID(projectId, ReportTriggerMode.SCHEDULE.name());
apiCountResult.setExecutedCount(executedCount);
long executedTimes = apiAutomationService.countExecuteTimesByProjectID(projectId, ReportTriggerMode.SCHEDULE.name());
apiCountResult.setExecutedTimes(executedTimes);
//统计 失败 成功 以及总数
List<ApiDataCountResult> allExecuteResult = apiScenarioReportService.countByProjectIdGroupByExecuteResult(projectId);
apiCountResult.countScheduleExecute(allExecuteResult);
long allCount = apiCountResult.getExecutedCount();
if (allCount != 0) {
float coveredRateNumber = (float) apiCountResult.getPassCount() * 100 / allCount;
if (executedTimes != 0) {
float passRateNumber = (float) apiCountResult.getPassCount() * 100 / executedTimes;
DecimalFormat df = new DecimalFormat("0.0");
apiCountResult.setPassRate(df.format(coveredRateNumber) + "%");
apiCountResult.setPassRate(df.format(passRateNumber) + "%");
}
//当前运行数运行中未运行

View File

@ -43,9 +43,9 @@ public class ApiCaseExecutionInfoService {
}
}
public long countExecutedTimesByProjectId(String projectId) {
public long countExecutedTimesByProjectId(String projectId, String executeType) {
ApiCaseExecutionInfoExample example = new ApiCaseExecutionInfoExample();
example.createCriteria().andProjectIdEqualTo(projectId);
example.createCriteria().andProjectIdEqualTo(projectId).andExecuteTypeEqualTo(executeType);
return apiCaseExecutionInfoMapper.countByExample(example);
}

View File

@ -1053,7 +1053,7 @@ public class ApiTestCaseService {
}
public Map<String, String> getApiCaseEnvironments(List<String> caseIds) {
if (CollectionUtils.isEmpty(caseIds)){
if (CollectionUtils.isEmpty(caseIds)) {
return null;
}
List<ParamsDTO> environments = extApiTestCaseMapper.getApiCaseEnvironments(caseIds);
@ -1061,7 +1061,7 @@ public class ApiTestCaseService {
return null;
}
try {
List<String> envIds = environments.stream().filter(t->StringUtils.isNotBlank(t.getValue()) && !StringUtils.equalsIgnoreCase(t.getValue(),"null")).map(ParamsDTO::getValue).collect(Collectors.toList());
List<String> envIds = environments.stream().filter(t -> StringUtils.isNotBlank(t.getValue()) && !StringUtils.equalsIgnoreCase(t.getValue(), "null")).map(ParamsDTO::getValue).collect(Collectors.toList());
ApiTestEnvironmentExample example = new ApiTestEnvironmentExample();
example.createCriteria().andIdIn(envIds);
List<ApiTestEnvironment> environmentList = apiTestEnvironmentMapper.selectByExample(example);
@ -1070,7 +1070,7 @@ public class ApiTestCaseService {
}
Map<String, String> envMap = environmentList.stream().collect(Collectors.toMap(ApiTestEnvironment::getId, ApiTestEnvironment::getName));
Map<String, String> caseEnvMap = environments.stream().filter(t->StringUtils.isNotBlank(t.getValue()) && !StringUtils.equalsIgnoreCase(t.getValue(),"null")).collect(HashMap::new, (m, v) -> m.put(v.getId(), v.getValue()), HashMap::putAll);
Map<String, String> caseEnvMap = environments.stream().filter(t -> StringUtils.isNotBlank(t.getValue()) && !StringUtils.equalsIgnoreCase(t.getValue(), "null")).collect(HashMap::new, (m, v) -> m.put(v.getId(), v.getValue()), HashMap::putAll);
caseEnvMap.forEach((k, v) -> {
if (envMap.containsKey(v)) {
caseEnvMap.put(k, envMap.get(v));
@ -1239,8 +1239,8 @@ public class ApiTestCaseService {
return extApiTestCaseMapper.getCaseCountById(id);
}
public long countExecutedTimesByProjectId(String projectId) {
return apiCaseExecutionInfoService.countExecutedTimesByProjectId(projectId);
public long countExecutedTimesByProjectId(String projectId, String executeType) {
return apiCaseExecutionInfoService.countExecutedTimesByProjectId(projectId, executeType);
}
public void setProjectIdInExecutionInfo() {

View File

@ -13,7 +13,7 @@
<span class="main-info-card-title">{{ $t("home.dashboard.public.executed_times") }}</span>
<div class="common-amount">
<span class="addition-num">
{{ countData.executedCount }}
{{ countData.executedTimes }}
</span>
</div>
</div>