fix(测试跟踪): 修复失败用例top10场景用例在不同测试计划内时没有分开统计的问题

--bug=1015301 --user=宋天阳 【测试跟踪】首页-测试计划失败用例top10,一个场景被多个测试计划关联,失败次数应该分别显示
https://www.tapd.cn/55049933/s/1210153
This commit is contained in:
song-tianyang 2022-07-25 15:43:46 +08:00 committed by 建国
parent 828b2d1e7d
commit bfd6db75a3
5 changed files with 30 additions and 88 deletions

View File

@ -308,9 +308,6 @@ public class ApiScenarioReportService {
testPlanApiScenario.setUpdateTime(System.currentTimeMillis()); testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario); testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
//增加场景的运行记录
scenarioExecutionInfoService.insertExecutionInfo(testPlanApiScenario.getId(), status, report.getTriggerMode());
// 更新场景状态 // 更新场景状态
ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(testPlanApiScenario.getApiScenarioId()); ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(testPlanApiScenario.getApiScenarioId());
if (scenario != null) { if (scenario != null) {

View File

@ -187,7 +187,11 @@ public class TestResultService {
} else { } else {
ApiScenarioWithBLOBs apiScenario = apiScenarioMapper.selectByPrimaryKey(scenarioReport.getScenarioId()); ApiScenarioWithBLOBs apiScenario = apiScenarioMapper.selectByPrimaryKey(scenarioReport.getScenarioId());
if (apiScenario != null) { if (apiScenario != null) {
if (StringUtils.equalsAnyIgnoreCase(dto.getRunMode(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) {
scenarioExecutionInfoService.insertExecutionInfo(dto.getTestId(), scenarioReport.getStatus(), scenarioReport.getTriggerMode());
} else {
scenarioExecutionInfoService.insertExecutionInfo(scenarioReport.getScenarioId(), scenarioReport.getStatus(), scenarioReport.getTriggerMode()); scenarioExecutionInfoService.insertExecutionInfo(scenarioReport.getScenarioId(), scenarioReport.getStatus(), scenarioReport.getTriggerMode());
}
environment = apiScenarioReportService.getEnvironment(apiScenario); environment = apiScenarioReportService.getEnvironment(apiScenario);
userName = apiAutomationService.getUser(apiScenario.getUserId()); userName = apiAutomationService.getUser(apiScenario.getUserId());
principal = apiAutomationService.getUser(apiScenario.getPrincipal()); principal = apiAutomationService.getUser(apiScenario.getPrincipal());

View File

@ -28,8 +28,6 @@ public interface ExtApiDefinitionExecResultMapper {
long countByTestCaseIDInProject(String projectId); long countByTestCaseIDInProject(String projectId);
List<ExecutedCaseInfoResult> findFaliureCaseInfoByProjectIDAndExecuteTimeAndLimitNumber(@Param("projectId") String projectId, @Param("startTimestamp") long startTimestamp);
List<ExecutedCaseInfoResult> findFaliureCaseInTestPlanByProjectIDAndExecuteTimeAndLimitNumber(@Param("projectId") String projectId, @Param("selectFunctionCase") boolean selectFunctionCase, @Param("startTimestamp") long startTimestamp); List<ExecutedCaseInfoResult> findFaliureCaseInTestPlanByProjectIDAndExecuteTimeAndLimitNumber(@Param("projectId") String projectId, @Param("selectFunctionCase") boolean selectFunctionCase, @Param("startTimestamp") long startTimestamp);
String selectExecResult(String resourceId); String selectExecResult(String resourceId);

View File

@ -110,8 +110,8 @@
testPlan.`name` AS testPlanName testPlan.`name` AS testPlanName
FROM test_plan_api_scenario testPlanScenario FROM test_plan_api_scenario testPlanScenario
INNER JOIN test_plan testPlan ON testPlan.id = testPlanScenario.test_plan_id) apiScene INNER JOIN test_plan testPlan ON testPlan.id = testPlanScenario.test_plan_id) apiScene
ON apiScene.api_scenario_id = executionInfo.source_id ON apiScene.id = executionInfo.source_id
INNER JOIN api_scenario scene ON scene.id = executionInfo.source_id INNER JOIN api_scenario scene ON scene.id = apiScene.api_scenario_id
WHERE scene.project_id = #{projectId} WHERE scene.project_id = #{projectId}
AND scene.`status` != 'Trash' AND scene.`status` != 'Trash'
@ -153,78 +153,6 @@
) showTable ) showTable
ORDER BY showTable.failureTimes DESC ORDER BY showTable.failureTimes DESC
</select> </select>
<select id="findFaliureCaseInfoByProjectIDAndExecuteTimeAndLimitNumber"
resultType="io.metersphere.api.dto.datacount.ExecutedCaseInfoResult">
SELECT *
FROM (
-- api_test_case 只查找测试计划执行的结果
SELECT testCase.testCaseID AS testCaseID,
testCase.id AS id,
testCase.testCaseName AS caseName,
testCase.testPlanName AS testPlan,
caseErrorCountData.dataCountNumber AS failureTimes,
'apiCase' AS caseType
FROM (SELECT testPlanCase.id AS testPlanCaseID,
testPlanCase.api_case_id as testCaseID,
apiCase.id AS id,
apiCase.`name` AS testCaseName,
testPlan.`name` AS testPlanName,
testPlanCase.update_time as updateTime
FROM api_test_case apiCase
inner join api_definition on api_definition.id = apiCase.api_definition_id
INNER JOIN test_plan_api_case testPlanCase ON testPlanCase.api_case_id = apiCase.id
INNER JOIN test_plan testPlan ON testPlan.id = testPlanCase.test_plan_id
and api_definition.status != 'Trash'
ORDER BY apiCase.create_time DESC) testCase
INNER JOIN (SELECT resource_id AS testPlanCaseID,
COUNT(id) AS dataCountNumber,
start_time AS executeTime
FROM api_definition_exec_result
WHERE resource_id IN (SELECT t2.id
FROM api_test_case t1
INNER JOIN test_plan_api_case t2 ON t1.id = t2.api_case_id
WHERE t1.project_id = #{projectId})
and `status` = 'error'
GROUP BY resource_id) caseErrorCountData
ON caseErrorCountData.testPlanCaseID = testCase.testPlanCaseID
WHERE testCase.updateTime >= #{startTimestamp}
UNION
SELECT ltr.test_id as testCaseID,
ltr.id AS id,
ltr.name as caseName,
tplt.testPlanName AS testPlan,
count(ltr.id) as failureTimes,
'load' as caseType
FROM load_test_report ltr
join load_test on load_test.id = ltr.test_id
JOIN (select tplc.load_case_id, group_concat(tp.`name`) AS testPlanName, tp.project_id
from test_plan_load_case tplc
join test_plan tp on tp.id = tplc.test_plan_id
GROUP BY tplc.load_case_id) tplt on tplt.load_case_id = ltr.test_id
WHERE load_test.project_id = #{projectId}
AND ltr.STATUS = 'Error'
and ltr.trigger_mode = 'TEST_PLAN_SCHEDULE'
AND ltr.create_time >= #{startTimestamp}
GROUP BY load_test.id
UNION
SELECT scene.id AS testCaseID,
scene.id AS id,
scene.`name` AS caseName,
apiScene.testPlanName AS testPlan,
count(report.id) AS failureTimes,
'scenario' AS caseType
FROM api_scenario_report report
INNER JOIN api_scenario scene ON report.scenario_id = scene.id
INNER JOIN(SELECT apiScene.api_scenario_id, group_concat(testPlan.`name`) AS testPlanName
FROM test_plan_api_scenario apiScene
INNER JOIN test_plan testPlan ON testPlan.id = apiScene.test_plan_id
GROUP BY apiScene.api_scenario_id) apiScene ON apiScene.api_scenario_id = scene.id
WHERE report.project_id = #{projectId}
AND scene.`status` != 'Trash'
AND ( report.STATUS = 'Error' OR report.STATUS = 'Fail' ) AND report.create_time >= #{startTimestamp}
GROUP BY scene.id) showTable
ORDER BY showTable.failureTimes DESC
</select>
<select id="selectExecResult" resultType="java.lang.String"> <select id="selectExecResult" resultType="java.lang.String">
select ader.status select ader.status
from api_definition_exec_result ader from api_definition_exec_result ader
@ -482,7 +410,9 @@
INNER JOIN api_test_case c ON r.resource_id = c.id INNER JOIN api_test_case c ON r.resource_id = c.id
AND c.`status` != 'Trash' AND c.`status` != 'Trash'
WHERE WHERE
r.status not in ('success','errorReportResult','errorReport') r.status not in ('success'
, 'errorReportResult'
, 'errorReport')
AND r.integrated_report_id = #{reportId} AND r.integrated_report_id = #{reportId}
ORDER BY ORDER BY
r.create_time ASC r.create_time ASC
@ -495,7 +425,9 @@
</select> </select>
<update id="updateAllStatus"> <update id="updateAllStatus">
update api_definition_exec_result set status="STOP" where status in ('Rerunning','Running','Waiting') update api_definition_exec_result
set status="STOP"
where status in ('Rerunning', 'Running', 'Waiting')
</update> </update>
</mapper> </mapper>

View File

@ -352,11 +352,20 @@
SELECT count(id) AS countNumber SELECT count(id) AS countNumber
FROM scenario_execution_info FROM scenario_execution_info
WHERE create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} WHERE create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp}
AND source_id in ( AND (
source_id in (
SELECT id SELECT id
FROM api_scenario FROM api_scenario
WHERE project_id = #{projectId} WHERE project_id = #{projectId}
); ) or
source_id in (
select id
FROM test_plan_api_scenario
WHERE api_scenario_id in (SELECT id
FROM api_scenario
WHERE project_id = #{projectId})
)
)
</select> </select>
<select id="countByProjectIdAndCreateAndByScheduleInThisWeek" resultType="java.lang.Long"> <select id="countByProjectIdAndCreateAndByScheduleInThisWeek" resultType="java.lang.Long">
@ -471,7 +480,9 @@
</select> </select>
<update id="updateAllStatus"> <update id="updateAllStatus">
update api_scenario_report set status="STOP" where status in ('Rerunning','Running','Waiting') update api_scenario_report
set status="STOP"
where status in ('Rerunning', 'Running', 'Waiting')
</update> </update>
</mapper> </mapper>