Skip to content

Commit

Permalink
fix(测试计划): 场景用例执行结果缺少脚本错误提示
Browse files Browse the repository at this point in the history
--bug=1042848 --user=陈建星 【测试计划】场景用例列表-执行结果无脚本错误提示 https://www.tapd.cn/55049933/s/1536669
  • Loading branch information
AgAngle authored and liuruibin committed Jun 25, 2024
1 parent 65e43c4 commit 362b175
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,13 @@ public void updateReportStatus(String reportId, String status) {
scenarioReport.setUpdateTime(System.currentTimeMillis());
apiScenarioReportMapper.updateByPrimaryKeySelective(scenarioReport);
}

public List<ApiScenarioReport> getApiScenarioReportByIds(List<String> reportIds) {
if (CollectionUtils.isEmpty(reportIds)) {
return List.of();
}
ApiScenarioReportExample reportExample = new ApiScenarioReportExample();
reportExample.createCriteria().andIdIn(reportIds);
return apiScenarioReportMapper.selectByExample(reportExample);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public class ApiScenarioService extends MoveNodeService {
@Resource
private ScheduleMapper scheduleMapper;
@Resource
private ApiScenarioReportService apiScenarioReportService;
@Resource
private ProjectMapper projectMapper;
@Resource
private ExtApiDefinitionMapper extApiDefinitionMapper;
Expand All @@ -158,8 +160,6 @@ public class ApiScenarioService extends MoveNodeService {
@Resource
private ApiCommonService apiCommonService;
@Resource
private ApiScenarioReportMapper apiScenarioReportMapper;
@Resource
private ApiScenarioNoticeService apiScenarioNoticeService;
@Resource
private ExtApiScenarioReportMapper extApiScenarioReportMapper;
Expand Down Expand Up @@ -211,9 +211,7 @@ private void processApiScenario(List<ApiScenarioDTO> scenarioLists) {
Map<String, Schedule> scheduleMap = schedules.stream().collect(Collectors.toMap(Schedule::getResourceId, t -> t));
//获取所有的lastResultId
List<String> lastResultIds = scenarioLists.stream().map(ApiScenarioDTO::getLastReportId).toList();
ApiScenarioReportExample reportExample = new ApiScenarioReportExample();
reportExample.createCriteria().andIdIn(lastResultIds);
List<ApiScenarioReport> reports = apiScenarioReportMapper.selectByExample(reportExample);
List<ApiScenarioReport> reports = apiScenarioReportService.getApiScenarioReportByIds(lastResultIds);
// 生成map key是id value是ScriptIdentifier 但是getScriptIdentifier为空的不放入
Map<String, String> reportMap = reports.stream().filter(report -> StringUtils.isNotBlank(report.getScriptIdentifier())).collect(Collectors.toMap(ApiScenarioReport::getId, ApiScenarioReport::getScriptIdentifier));
scenarioLists.forEach(item -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@ public class TestPlanApiScenarioPageResponse implements Serializable {

@Schema(description = "场景用例的id")
private String apiScenarioId;

@Schema(description = "脚本错误标识")
private String scriptIdentifier;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.metersphere.api.service.ApiBatchRunBaseService;
import io.metersphere.api.service.ApiExecuteService;
import io.metersphere.api.service.scenario.ApiScenarioModuleService;
import io.metersphere.api.service.scenario.ApiScenarioReportService;
import io.metersphere.api.service.scenario.ApiScenarioRunService;
import io.metersphere.api.service.scenario.ApiScenarioService;
import io.metersphere.functional.dto.FunctionalCaseModuleCountDTO;
Expand Down Expand Up @@ -50,6 +51,7 @@
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.jetbrains.annotations.NotNull;
import org.mybatis.spring.SqlSessionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -104,6 +106,8 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
private ApiScenarioMapper apiScenarioMapper;
@Resource
private ApiScenarioModuleMapper apiScenarioModuleMapper;
@Resource
private ApiScenarioReportService apiScenarioReportService;

@Override
public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
Expand Down Expand Up @@ -354,10 +358,19 @@ private void buildApiScenarioResponse(List<TestPlanApiScenarioPageResponse> apiS
Map<String, String> projectMap = getProject(apiScenarioList);
Map<String, String> userMap = getUserMap(apiScenarioList);
Map<String, String> moduleNameMap = getModuleName(apiScenarioList);
handleScenarioAndEnv(apiScenarioList, projectMap, userMap, testPlanId, moduleNameMap);
Map<String, String> reportMap = getReportMap(apiScenarioList);
handleScenarioAndEnv(apiScenarioList, projectMap, userMap, testPlanId, moduleNameMap, reportMap);
}
}

private Map<String, String> getReportMap(List<TestPlanApiScenarioPageResponse> apiScenarioList) {
List<String> reportIds = apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getLastExecReportId).toList();
List<ApiScenarioReport> reports = apiScenarioReportService.getApiScenarioReportByIds(reportIds);
// 生成map key是id value是ScriptIdentifier 但是getScriptIdentifier为空的不放入
return reports.stream().filter(report -> StringUtils.isNotBlank(report.getScriptIdentifier()))
.collect(Collectors.toMap(ApiScenarioReport::getId, ApiScenarioReport::getScriptIdentifier));
}

private Map<String, String> getModuleName(List<TestPlanApiScenarioPageResponse> apiScenarioList) {
List<String> moduleIds = apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getModuleId).distinct().toList();
ApiScenarioModuleExample moduleExample = new ApiScenarioModuleExample();
Expand All @@ -367,7 +380,9 @@ private Map<String, String> getModuleName(List<TestPlanApiScenarioPageResponse>
return moduleNameMap;
}

private void handleScenarioAndEnv(List<TestPlanApiScenarioPageResponse> apiScenarioList, Map<String, String> projectMap, Map<String, String> userMap, String testPlanId, Map<String, String> moduleNameMap) {
private void handleScenarioAndEnv(List<TestPlanApiScenarioPageResponse> apiScenarioList, Map<String, String> projectMap,
Map<String, String> userMap, String testPlanId, Map<String, String> moduleNameMap,
Map<String, String> reportMap) {
//获取二级节点环境
List<TestPlanCollectionEnvDTO> secondEnv = extTestPlanCollectionMapper.selectSecondCollectionEnv(CaseType.SCENARIO_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID, testPlanId);
Map<String, TestPlanCollectionEnvDTO> secondEnvMap = secondEnv.stream().collect(Collectors.toMap(TestPlanCollectionEnvDTO::getId, item -> item));
Expand All @@ -383,6 +398,7 @@ private void handleScenarioAndEnv(List<TestPlanApiScenarioPageResponse> apiScena
item.setProjectName(projectMap.get(item.getProjectId()));
item.setCreateUserName(userMap.get(item.getCreateUser()));
item.setExecuteUserName(userMap.get(item.getExecuteUser()));
item.setScriptIdentifier(reportMap.get(item.getLastExecReportId()));
item.setModuleName(StringUtils.isNotBlank(moduleNameMap.get(item.getModuleId())) ? moduleNameMap.get(item.getModuleId()) : Translator.get("api_unplanned_scenario"));
if (secondEnvMap.containsKey(item.getTestPlanCollectionId())) {
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
:module-type="ReportEnum.API_REPORT"
:status="record.lastExecResult"
:class="[!record.lastExecReportId ? '' : 'cursor-pointer']"
:script-identifier="record.scriptIdentifier"
@click="showReport(record)"
/>
</template>
Expand Down Expand Up @@ -228,7 +229,7 @@
options: lastReportStatusListOptions.value,
filterSlotName: FilterSlotNameEnum.API_TEST_CASE_API_LAST_EXECUTE_STATUS,
},
width: 150,
width: 200,
showDrag: true,
},
{
Expand Down

0 comments on commit 362b175

Please sign in to comment.