fix(接口测试): 改进接口测试首页的接口用例统计方法

--bug=1021930 --user=宋天阳 【接口测试】接口首页 - 接口用例数量统计 - 未通过用例数统计不对
https://www.tapd.cn/55049933/s/1327734
This commit is contained in:
song-tianyang 2023-01-16 15:50:10 +08:00 committed by fit2-zhao
parent 22f7f58e30
commit cf4287d690
3 changed files with 46 additions and 44 deletions

View File

@ -467,19 +467,19 @@
</foreach>
</if>
<if test="request.redirectFilter == 'unexecuteCount' ">
and (t1.status IS NULL or t1.status NOT IN ('SUCCESS','ERROR','FAKE_ERROR') )
and (t3.status IS NULL or t3.status NOT IN ('SUCCESS','ERROR','FAKE_ERROR') )
</if>
<if test="request.redirectFilter == 'executionPassCount' ">
and t1.status = 'SUCCESS'
and t3.status = 'SUCCESS'
</if>
<if test="request.redirectFilter == 'executionFailedCount' ">
and t1.status = 'ERROR'
and t3.status = 'ERROR'
</if>
<if test="request.redirectFilter == 'fakeErrorCount' ">
and t1.status = 'FAKE_ERROR'
and t3.status = 'FAKE_ERROR'
</if>
<if test="request.redirectFilter == 'executedCount' ">
and t1.status IN ('SUCCESS','ERROR','FAKE_ERROR')
and t3.status IN ('SUCCESS','ERROR','FAKE_ERROR')
</if>
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
@ -1022,14 +1022,18 @@
from api_test_case
where id = #{0}
</select>
<select id="selectExecuteResultByProjectId"
resultType="io.metersphere.api.dto.datacount.response.ExecuteResultCountDTO">
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
SELECT
execResult.`status` AS execResult,
count(testCase.id) AS `count`
FROM
api_test_case testCase
LEFT JOIN api_definition_exec_result execResult ON execResult.id = testCase.last_result_id
WHERE
( testCase.`status` IS NULL OR testCase.`status` != 'Trash' )
AND testCase.api_definition_id IN (
SELECT id FROM api_definition
WHERE project_id = #{projectId}
<if test="versionId != null">
AND version_id = #{versionId}
@ -1038,7 +1042,9 @@
AND latest IS TRUE
</if>
)
GROUP BY `status`
GROUP BY
execResult.`status`;
</select>
<select id="caseList" resultType="io.metersphere.base.domain.ApiTestCaseWithBLOBs">
SELECT

View File

@ -58,9 +58,7 @@ public class ApiHomeController {
@GetMapping("/api/count/{projectId}/{versionId}")
public ApiDataCountDTO apiCount(@PathVariable String projectId, @PathVariable String versionId) {
if (StringUtils.equalsIgnoreCase(versionId, "default")) {
versionId = null;
}
versionId = this.initializationVersionId(versionId);
ApiDataCountDTO apiCountResult = new ApiDataCountDTO();
List<ApiDataCountResult> countResultByProtocolList = apiDefinitionService.countProtocolByProjectID(projectId, versionId);
apiCountResult.countProtocol(countResultByProtocolList);
@ -103,9 +101,7 @@ public class ApiHomeController {
@GetMapping("/api/case/count/{projectId}/{versionId}")
public ApiDataCountDTO apiCaseCount(@PathVariable String projectId, @PathVariable String versionId) {
if (StringUtils.equalsIgnoreCase(versionId, "default")) {
versionId = null;
}
versionId = this.initializationVersionId(versionId);
ApiDataCountDTO apiCountResult = new ApiDataCountDTO();
List<ApiDataCountResult> countResultList = apiTestCaseService.countProtocolByProjectID(projectId, versionId);
apiCountResult.countProtocol(countResultList);
@ -146,9 +142,7 @@ public class ApiHomeController {
@GetMapping("/scenario/count/{projectId}/{versionId}")
public ApiDataCountDTO scenarioCount(@PathVariable String projectId, @PathVariable String versionId) {
if (StringUtils.equalsIgnoreCase(versionId, "default")) {
versionId = null;
}
versionId = this.initializationVersionId(versionId);
ApiDataCountDTO apiCountResult = new ApiDataCountDTO();
long scenarioCountNumber = apiAutomationService.countScenarioByProjectID(projectId, versionId);
apiCountResult.setTotal(scenarioCountNumber);
@ -190,11 +184,8 @@ public class ApiHomeController {
@GetMapping("/schedule/task/count/{projectId}/{versionId}")
public ApiDataCountDTO scheduleTaskCount(@PathVariable String projectId, @PathVariable String versionId) {
if (StringUtils.equalsIgnoreCase(versionId, "default")) {
versionId = null;
}
versionId = this.initializationVersionId(versionId);
List<Schedule> allScenarioScheduleList = baseScheduleService.selectScenarioTaskByProjectId(projectId, versionId);
ApiDataCountDTO apiCountResult = new ApiDataCountDTO();
long allTaskCount = allScenarioScheduleList.size();
apiCountResult.setTotal(allTaskCount);
@ -246,9 +237,7 @@ public class ApiHomeController {
@PostMapping("/runningTask/{projectId}/{versionId}/{goPage}/{pageSize}")
public Pager<List<TaskInfoResult>> runningTask(@PathVariable String projectId, @PathVariable String versionId, @PathVariable int goPage, @PathVariable int pageSize) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
if (StringUtils.equalsIgnoreCase(versionId, "default")) {
versionId = null;
}
versionId = this.initializationVersionId(versionId);
List<TaskInfoResult> resultList = taskService.findScenarioAndSwaggerRunningTaskInfoByProjectID(projectId, versionId);
int dataIndex = 1;
for (TaskInfoResult taskInfo :
@ -266,9 +255,7 @@ public class ApiHomeController {
@GetMapping("/failure/case/about/plan/{projectId}/{versionId}/{selectFunctionCase}/{limitNumber}/{goPage}/{pageSize}")
public Pager<List<ExecutedCaseInfoDTO>> failureCaseAboutTestPlan(@PathVariable String projectId, @PathVariable String versionId, @PathVariable boolean selectFunctionCase,
@PathVariable int limitNumber, @PathVariable int goPage, @PathVariable int pageSize) {
if (StringUtils.equalsIgnoreCase(versionId, "default")) {
versionId = null;
}
versionId = this.initializationVersionId(versionId);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
List<ExecutedCaseInfoResult> selectDataList = apiDefinitionExecResultService.findFailureCaseInfoByProjectIDAndLimitNumberInSevenDays(projectId, versionId, selectFunctionCase, limitNumber);
List<ExecutedCaseInfoDTO> returnList = new ArrayList<>(selectDataList.size());
@ -288,4 +275,13 @@ public class ApiHomeController {
}
return PageUtils.setPageInfo(page, returnList);
}
//初始化版本ID
private String initializationVersionId(String versionId) {
if (StringUtils.equalsIgnoreCase(versionId, "default")) {
return null;
} else {
return versionId;
}
}
}

View File

@ -32,7 +32,7 @@
:disabled="isReadOnly"
v-model="scope.row.type"
size="mini"
@change="typeChange(item)">
@change="typeChange(scope.row)">
<el-option value="text" />
<el-option value="file" />
<el-option value="json" />
@ -437,7 +437,7 @@ export default {
urlEncode: this.urlEncode,
uuid: this.uuid(),
valid: false,
value: null
value: null,
})
);
}
@ -488,11 +488,11 @@ export default {
},
typeChange(item) {
if (item.type === 'file') {
item.contentType = 'application/octet-stream';
this.$set(item, 'contentType', 'application/octet-stream');
} else if (item.type === 'text') {
item.contentType = 'text/plain';
this.$set(item, 'contentType', 'text/plain');
} else {
item.contentType = 'application/json';
this.$set(item, 'contentType', 'application/json');
}
this.reload();
},
@ -540,7 +540,7 @@ export default {
urlEncode: this.urlEncode,
uuid: this.uuid(),
valid: false,
value: null
value: null,
})
);
}