test(接口测试): 调整接口覆盖率计算的单元测试

This commit is contained in:
Jianguo-Genius 2024-11-26 14:49:29 +08:00 committed by 刘瑞斌
parent bde39eb0c5
commit f6daf2fe8d
4 changed files with 59 additions and 46 deletions

View File

@ -45,6 +45,6 @@
where scenario.project_id = #{0}
AND scenario.deleted IS FALSE
AND step.step_type IN ('API', 'API_CASE', 'CUSTOM_REQUEST')
AND JSON_EXTRACT(step.config, '$.protocol') = 'http'
AND JSON_UNQUOTE(JSON_EXTRACT(LOWER(step.config), '$.protocol')) = 'http'
</select>
</mapper>

View File

@ -2635,7 +2635,6 @@ public class ApiScenarioService extends MoveNodeService {
return Collections.emptyList();
}
// 分批处理配置请求 ID 列表
Map<String, Set<String>> methodPathMap = new HashMap<>();
SubListUtils.dealForSubList(requestIdList, 200, batchIds -> {

View File

@ -25,13 +25,9 @@ public class ApiDefinitionUtils {
if (StringUtils.isEmpty(customRequestUrl)) {
continue;
}
if (customRequestUrl.startsWith("/")) {
customRequestUrl = customRequestUrl.substring(1);
}
if (StringUtils.isNotEmpty(customRequestUrl)) {
if (customRequestUrl.contains("?")) {
customRequestUrl = customRequestUrl.substring(0, customRequestUrl.indexOf("?"));
}
customRequestUrl = pretreatmentUrl(customRequestUrl);
String[] customUrlArr = customRequestUrl.split("/");
if (StringUtils.startsWithAny(customRequestUrl.toLowerCase(), "https://", "http://")
@ -67,14 +63,23 @@ public class ApiDefinitionUtils {
if (isFetch) {
return true;
}
}
}
}
}
return false;
}
private static String pretreatmentUrl(String customRequestUrl) {
if (customRequestUrl.startsWith("/")) {
customRequestUrl = customRequestUrl.substring(1);
}
if (customRequestUrl.contains("?")) {
customRequestUrl = customRequestUrl.substring(0, customRequestUrl.indexOf("?"));
}
return customRequestUrl;
}
private static boolean isRestUrlParam(String urlParam) {
return !StringUtils.startsWith(urlParam, "{") || !StringUtils.endsWith(urlParam, "}") || StringUtils.equals(urlParam, "{}");
}

View File

@ -165,6 +165,9 @@ public class ApiCalculateTest extends BaseTest {
stepRequest.setName(apiTestCase.getName() + "_step");
stepRequest.setRefType(ApiScenarioStepRefType.REF.name());
stepRequest.setProjectId(project.getId());
stepRequest.setConfig(new HashMap<>() {{
this.put("protocol", "http");
}});
steps.add(stepRequest);
steptDetailMap.put(stepRequest.getId(), JSON.parseObject(ApiDataUtils.toJSONString(msHttpElement)));
}
@ -179,6 +182,9 @@ public class ApiCalculateTest extends BaseTest {
stepRequest.setName("custom_step");
stepRequest.setRefType(ApiScenarioStepRefType.DIRECT.name());
stepRequest.setProjectId(project.getId());
stepRequest.setConfig(new HashMap<>() {{
this.put("protocol", "http");
}});
steps.add(stepRequest);
MsHTTPElement customElement = MsHTTPElementTest.getMsHttpElement();
@ -197,6 +203,9 @@ public class ApiCalculateTest extends BaseTest {
stepRequest.setName(resultData.getName() + "_step");
stepRequest.setRefType(ApiScenarioStepRefType.REF.name());
stepRequest.setProjectId(project.getId());
stepRequest.setConfig(new HashMap<>() {{
this.put("protocol", "http");
}});
steps.add(stepRequest);
steptDetailMap.put(stepRequest.getId(), JSON.parseObject(ApiDataUtils.toJSONString(msHttpElement)));
}
@ -226,12 +235,12 @@ public class ApiCalculateTest extends BaseTest {
Assertions.assertEquals(16, apiCoverageDTO.getUnCoverWithApiCase());
Assertions.assertEquals(apiCoverageDTO.getApiCaseCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiCase(), apiCoverageDTO.getAllApiCount()));
Assertions.assertEquals(4, apiCoverageDTO.getCoverWithApiScenario());
Assertions.assertEquals(16, apiCoverageDTO.getUnCoverWithApiScenario());
Assertions.assertEquals(8, apiCoverageDTO.getCoverWithApiScenario());
Assertions.assertEquals(12, apiCoverageDTO.getUnCoverWithApiScenario());
Assertions.assertEquals(apiCoverageDTO.getScenarioCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiScenario(), apiCoverageDTO.getAllApiCount()));
Assertions.assertEquals(6, apiCoverageDTO.getCoverWithApiDefinition());
Assertions.assertEquals(14, apiCoverageDTO.getUnCoverWithApiDefinition());
Assertions.assertEquals(10, apiCoverageDTO.getCoverWithApiDefinition());
Assertions.assertEquals(10, apiCoverageDTO.getUnCoverWithApiDefinition());
Assertions.assertEquals(apiCoverageDTO.getApiCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiDefinition(), apiCoverageDTO.getAllApiCount()));
Assertions.assertEquals("0.00%", CalculateUtils.reportPercentage(0, 0));