fix(接口测试): 修改计算接口覆盖率的逻辑
--bug=1017413 --user=宋天阳 [接口测试]github#18292场景接口覆盖率在开启 “url允许重复” 后,计算逻辑有误 https://www.tapd.cn/55049933/s/1283443
This commit is contained in:
parent
55028ced83
commit
cce5cc9797
|
@ -313,7 +313,7 @@ public class APITestController {
|
|||
*/
|
||||
List<ApiDefinition> apiNoCaseList = apiDefinitionService.selectEffectiveIdByProjectIdAndHaveNotCase(projectId);
|
||||
Map<String, Map<String, String>> scenarioUrlList = apiAutomationService.selectScenarioUseUrlByProjectId(projectId);
|
||||
int apiInScenario = apiAutomationService.getApiIdInScenario(projectId, scenarioUrlList, apiNoCaseList).size();
|
||||
int apiInScenario = apiAutomationService.getApiIdInScenario(scenarioUrlList, apiNoCaseList).size();
|
||||
|
||||
try {
|
||||
if (effectiveApiCount == 0) {
|
||||
|
|
|
@ -1857,7 +1857,7 @@ public class ApiAutomationService {
|
|||
if (CollectionUtils.isEmpty(apiList)) {
|
||||
return coverage;
|
||||
}
|
||||
int urlContainsCount = this.getApiIdInScenario(projectId, scenarioUrlMap, apiList).size();
|
||||
int urlContainsCount = this.getApiIdInScenario(scenarioUrlMap, apiList).size();
|
||||
coverage.setCoverate(urlContainsCount);
|
||||
coverage.setNotCoverate(apiList.size() - urlContainsCount);
|
||||
float coverageRageNumber = (float) urlContainsCount * 100 / apiList.size();
|
||||
|
@ -1866,30 +1866,18 @@ public class ApiAutomationService {
|
|||
return coverage;
|
||||
}
|
||||
|
||||
public List<String> getApiIdInScenario(String projectId, Map<String, Map<String, String>> scenarioUrlMap, List<ApiDefinition> apiList) {
|
||||
public List<String> getApiIdInScenario(Map<String, Map<String, String>> scenarioUrlMap, List<ApiDefinition> apiList) {
|
||||
List<String> apiIdList = new ArrayList<>();
|
||||
if (MapUtils.isNotEmpty(scenarioUrlMap) && CollectionUtils.isNotEmpty(apiList)) {
|
||||
ProjectApplication urlRepeatableConfig = projectApplicationService.getProjectApplication(projectId, ProjectApplicationType.URL_REPEATABLE.name());
|
||||
boolean isUrlRepeatable = BooleanUtils.toBoolean(urlRepeatableConfig.getTypeValue());
|
||||
for (ApiDefinition model : apiList) {
|
||||
if (StringUtils.equalsIgnoreCase(model.getProtocol(), "http")) {
|
||||
Map<String, String> stepIdAndUrlMap = scenarioUrlMap.get(model.getMethod());
|
||||
if (stepIdAndUrlMap != null) {
|
||||
if (isUrlRepeatable) {
|
||||
String url = stepIdAndUrlMap.get(model.getId());
|
||||
if (StringUtils.isNotEmpty(url)) {
|
||||
boolean urlMatched = MockApiUtils.isUrlMatch(model.getPath(), url);
|
||||
if (urlMatched) {
|
||||
apiIdList.add(model.getId());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Collection<String> scenarioUrlList = scenarioUrlMap.get(model.getMethod()).values();
|
||||
boolean matchedUrl = MockApiUtils.isUrlInList(model.getPath(), scenarioUrlList);
|
||||
if (matchedUrl) {
|
||||
apiIdList.add(model.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Map<String, String> stepIdAndUrlMap = scenarioUrlMap.get("MS_NOT_HTTP");
|
||||
|
|
|
@ -370,7 +370,7 @@ public class ApiDefinitionService {
|
|||
}
|
||||
//如果查询条件中有未覆盖/已覆盖, 则需要解析出没有用例的接口中,有多少是符合场景覆盖规律的。然后将这些接口的id作为查询参数
|
||||
Map<String, Map<String, String>> scenarioUrlList = apiAutomationService.selectScenarioUseUrlByProjectId(request.getProjectId());
|
||||
List<String> apiIdInScenario = apiAutomationService.getApiIdInScenario(request.getProjectId(), scenarioUrlList, definitionList);
|
||||
List<String> apiIdInScenario = apiAutomationService.getApiIdInScenario(scenarioUrlList, definitionList);
|
||||
if (CollectionUtils.isNotEmpty(apiIdInScenario)) {
|
||||
request.setCoverageIds(apiIdInScenario);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue