feat(接口测试): 更改测试计划首页接口数量统计卡片中已覆盖接口的计算方式
--bug=1015151 --user=宋天阳 【接口测试】未开启url可重复,场景里添加了自定义请求覆盖了用例url,首页-接口数量统计,已覆盖接口没有增加 https://www.tapd.cn/55049933/s/1208066
This commit is contained in:
parent
c6044ec193
commit
d5c34bb99e
|
@ -308,18 +308,28 @@ public class APITestController {
|
|||
CoverageDTO coverage = new CoverageDTO();
|
||||
/**
|
||||
* 接口覆盖率
|
||||
* 接口有案例/被场景引用 : 所有的接口
|
||||
* 有案例的接口/没有案例确被场景引用 (apiHasCase + apiInScenario) : 所有的接口(effectiveApiCount)
|
||||
*/
|
||||
long effectiveApiCount = apiDefinitionService.countEffectiveByProjectId(projectId);
|
||||
long sourceIdCount = apiDefinitionService.countQuotedApiByProjectId(projectId);
|
||||
long apiHasCase = apiDefinitionService.countApiByProjectIdAndHasCase(projectId);
|
||||
|
||||
|
||||
/**
|
||||
* 计算没有用例接口的覆盖数量
|
||||
*/
|
||||
List<ApiDefinition> apiNoCaseList = apiDefinitionService.selectEffectiveIdByProjectIdAndHaveNotCase(projectId);
|
||||
Map<String, Map<String, String>> scenarioUrlList = apiAutomationService.selectScenarioUseUrlByProjectId(projectId);
|
||||
int apiInScenario = apiAutomationService.countApiInScenario(projectId, scenarioUrlList, apiNoCaseList);
|
||||
|
||||
try {
|
||||
if (effectiveApiCount == 0) {
|
||||
coverage.setCoverate(0);
|
||||
coverage.setNotCoverate(0);
|
||||
} else {
|
||||
coverage.setCoverate(sourceIdCount);
|
||||
coverage.setNotCoverate(effectiveApiCount - sourceIdCount);
|
||||
float coverageRageNumber = (float) sourceIdCount * 100 / effectiveApiCount;
|
||||
long quotedApiCount = apiHasCase + apiInScenario;
|
||||
coverage.setCoverate(quotedApiCount);
|
||||
coverage.setNotCoverate(effectiveApiCount - quotedApiCount);
|
||||
float coverageRageNumber = (float) quotedApiCount * 100 / effectiveApiCount;
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
coverage.setRateOfCoverage(df.format(coverageRageNumber) + "%");
|
||||
}
|
||||
|
|
|
@ -1767,20 +1767,30 @@ public class ApiAutomationService {
|
|||
* <p>
|
||||
* 匹配场景中用到的路径
|
||||
*
|
||||
* @param scenarioUrlMap 场景使用到的url key:method
|
||||
* @param allEffectiveApiList 接口集合(id / path 必须有数据)
|
||||
* @param scenarioUrlMap 场景使用到的url key:method
|
||||
* @param apiList 接口集合(id / path 必须有数据)
|
||||
* @return
|
||||
*/
|
||||
public CoverageDTO countInterfaceCoverage(String projectId, Map<String, Map<String, String>> scenarioUrlMap, List<ApiDefinition> allEffectiveApiList) {
|
||||
public CoverageDTO countInterfaceCoverage(String projectId, Map<String, Map<String, String>> scenarioUrlMap, List<ApiDefinition> apiList) {
|
||||
CoverageDTO coverage = new CoverageDTO();
|
||||
if (CollectionUtils.isEmpty(allEffectiveApiList)) {
|
||||
if (CollectionUtils.isEmpty(apiList)) {
|
||||
return coverage;
|
||||
}
|
||||
int urlContainsCount = this.countApiInScenario(projectId, scenarioUrlMap, apiList);
|
||||
coverage.setCoverate(urlContainsCount);
|
||||
coverage.setNotCoverate(apiList.size() - urlContainsCount);
|
||||
float coverageRageNumber = (float) urlContainsCount * 100 / apiList.size();
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
coverage.setRateOfCoverage(df.format(coverageRageNumber) + "%");
|
||||
return coverage;
|
||||
}
|
||||
|
||||
public int countApiInScenario(String projectId, Map<String, Map<String, String>> scenarioUrlMap, List<ApiDefinition> apiList) {
|
||||
int urlContainsCount = 0;
|
||||
if (MapUtils.isNotEmpty(scenarioUrlMap)) {
|
||||
ProjectApplication urlRepeatableConfig = projectApplicationService.getProjectApplication(projectId, ProjectApplicationType.URL_REPEATABLE.name());
|
||||
boolean isUrlRepeatable = BooleanUtils.toBoolean(urlRepeatableConfig.getTypeValue());
|
||||
for (ApiDefinition model : allEffectiveApiList) {
|
||||
for (ApiDefinition model : apiList) {
|
||||
if (StringUtils.equalsIgnoreCase(model.getProtocol(), "http")) {
|
||||
Map<String, String> stepIdAndUrlMap = scenarioUrlMap.get(model.getMethod());
|
||||
if (stepIdAndUrlMap != null) {
|
||||
|
@ -1808,12 +1818,7 @@ public class ApiAutomationService {
|
|||
}
|
||||
}
|
||||
}
|
||||
coverage.setCoverate(urlContainsCount);
|
||||
coverage.setNotCoverate(allEffectiveApiList.size() - urlContainsCount);
|
||||
float coverageRageNumber = (float) urlContainsCount * 100 / allEffectiveApiList.size();
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
coverage.setRateOfCoverage(df.format(coverageRageNumber) + "%");
|
||||
return coverage;
|
||||
return urlContainsCount;
|
||||
}
|
||||
|
||||
public ScenarioEnv getApiScenarioProjectId(String id) {
|
||||
|
|
|
@ -2162,6 +2162,10 @@ public class ApiDefinitionService {
|
|||
return extApiDefinitionMapper.selectEffectiveIdByProjectId(projectId);
|
||||
}
|
||||
|
||||
public List<ApiDefinition> selectEffectiveIdByProjectIdAndHaveNotCase(String projectId) {
|
||||
return extApiDefinitionMapper.selectEffectiveIdByProjectIdAndHaveNotCase(projectId);
|
||||
}
|
||||
|
||||
public List<ApiDefinitionWithBLOBs> preparedUrl(String projectId, String method, String baseUrlSuffix) {
|
||||
if (StringUtils.isEmpty(baseUrlSuffix)) {
|
||||
return new ArrayList<>();
|
||||
|
@ -2372,8 +2376,8 @@ public class ApiDefinitionService {
|
|||
}
|
||||
}
|
||||
|
||||
public long countQuotedApiByProjectId(String projectId) {
|
||||
return extApiDefinitionMapper.countQuotedApiByProjectId(projectId);
|
||||
public long countApiByProjectIdAndHasCase(String projectId) {
|
||||
return extApiDefinitionMapper.countApiByProjectIdAndHasCase(projectId);
|
||||
}
|
||||
|
||||
public int getRelationshipCount(String id) {
|
||||
|
|
|
@ -75,7 +75,7 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
Long getLastOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder);
|
||||
|
||||
long countQuotedApiByProjectId(String projectId);
|
||||
long countApiByProjectIdAndHasCase(String projectId);
|
||||
|
||||
List<RelationshipGraphData.Node> getForGraph(@Param("ids") Set<String> ids);
|
||||
|
||||
|
@ -100,4 +100,6 @@ public interface ExtApiDefinitionMapper {
|
|||
List<ApiDefinitionWithBLOBs> selectRepeatByProtocol(@Param("names") List<String> names, @Param("protocol") String protocol, @Param("projectId") String projectId);
|
||||
|
||||
int countById(String id);
|
||||
|
||||
List<ApiDefinition> selectEffectiveIdByProjectIdAndHaveNotCase(String projectId);
|
||||
}
|
||||
|
|
|
@ -658,6 +658,15 @@
|
|||
AND status != 'Trash' AND latest = 1
|
||||
</select>
|
||||
|
||||
<select id="selectEffectiveIdByProjectIdAndHaveNotCase" resultType="io.metersphere.base.domain.ApiDefinition">
|
||||
select id, path, method, protocol
|
||||
from api_definition
|
||||
WHERE project_id = #{0}
|
||||
AND status != 'Trash' AND latest = 1
|
||||
AND id NOT IN (select api_definition_id FROM api_test_case WHERE project_id = #{0}
|
||||
AND (status IS NULL
|
||||
or status != 'Trash'))
|
||||
</select>
|
||||
<select id="moduleCount" resultType="java.lang.Integer">
|
||||
select count(id) from api_definition
|
||||
<include refid="queryWhereCondition"/>
|
||||
|
@ -955,22 +964,15 @@
|
|||
order by `order` desc limit 1;
|
||||
</select>
|
||||
|
||||
<select id="countQuotedApiByProjectId" resultType="java.lang.Long">
|
||||
<select id="countApiByProjectIdAndHasCase" resultType="java.lang.Long">
|
||||
SELECT COUNT(id)
|
||||
FROM api_definition
|
||||
WHERE project_id = #{0}
|
||||
AND `status` != 'Trash'
|
||||
AND (
|
||||
id IN (
|
||||
SELECT reference_id FROM api_scenario_reference_id WHERE api_scenario_id in (
|
||||
SELECT id FROM api_scenario WHERE `status` is null or `status` != 'Trash'
|
||||
)
|
||||
)
|
||||
OR
|
||||
AND
|
||||
id IN (
|
||||
SELECT api_definition_id FROM api_test_case WHERE `status` is null or `status` != 'Trash'
|
||||
)
|
||||
)
|
||||
AND latest = 1
|
||||
</select>
|
||||
<select id="getForGraph" resultType="io.metersphere.dto.RelationshipGraphData$Node">
|
||||
|
|
Loading…
Reference in New Issue