fix(接口测试): 修复因优化接口测试首页统计时出现的部分数据统计错误

This commit is contained in:
song-tianyang 2023-08-31 11:26:01 +08:00 committed by fit2-zhao
parent f96b91eb94
commit 4f7d1af0f8
4 changed files with 23 additions and 3 deletions

View File

@ -27,6 +27,8 @@ public interface ExtApiTestCaseMapper {
List<ApiDataCountResult> countProtocolByProjectID(@Param("projectId") String projectId, @Param("versionId") String versionId); List<ApiDataCountResult> countProtocolByProjectID(@Param("projectId") String projectId, @Param("versionId") String versionId);
long countByProjectID(@Param("projectId") String projectId, @Param("versionId") String versionId);
long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("versionId") String versionId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("versionId") String versionId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp);
List<ApiTestCaseInfo> getRequest(@Param("request") ApiTestCaseRequest request); List<ApiTestCaseInfo> getRequest(@Param("request") ApiTestCaseRequest request);

View File

@ -694,6 +694,21 @@
</if> </if>
GROUP BY apiDef.protocol GROUP BY apiDef.protocol
</select> </select>
<select id="countByProjectID" resultType="java.lang.Long">
SELECT COUNT(testCase.id) AS countNumber
FROM api_test_case testCase
INNER JOIN api_definition apiDef ON testCase.api_definition_id = apiDef.id
WHERE testCase.project_id = #{projectId}
AND (testCase.status IS NULL or testCase.status != "Trash")
<if test="versionId != null">
AND apiDef.version_id = #{versionId}
</if>
<if test="versionId == null">
AND apiDef.latest = 1
</if>
</select>
<select id="findApiUrlAndMethodById" resultType="io.metersphere.base.domain.ApiDefinition"> <select id="findApiUrlAndMethodById" resultType="io.metersphere.base.domain.ApiDefinition">
SELECT method, path SELECT method, path
FROM api_definition FROM api_definition

View File

@ -166,13 +166,13 @@ public class ApiHomeController {
public ApiDataCountDTO caseCovered(@PathVariable String projectId, @PathVariable String versionId) throws Exception { public ApiDataCountDTO caseCovered(@PathVariable String projectId, @PathVariable String versionId) throws Exception {
versionId = this.initializationVersionId(versionId); versionId = this.initializationVersionId(versionId);
ApiDataCountDTO apiCountResult = new ApiDataCountDTO(); ApiDataCountDTO apiCountResult = new ApiDataCountDTO();
long allCount = apiTestCaseService.countByProjectID(projectId, versionId);
//两个大数据量下耗时比较长的查询同时进行 //两个大数据量下耗时比较长的查询同时进行
CountDownLatch countDownLatch = new CountDownLatch(2); CountDownLatch countDownLatch = new CountDownLatch(2);
try { try {
//未覆盖 已覆盖 统计当前接口下是否含有案例 //未覆盖 已覆盖 统计当前接口下是否含有案例
List<ApiDataCountResult> countResultByApiCoverageList = apiDefinitionService.countApiCoverageByProjectID(projectId, versionId); List<ApiDataCountResult> countResultByApiCoverageList = apiDefinitionService.countApiCoverageByProjectID(projectId, versionId);
apiCountResult.countApiCoverage(countResultByApiCoverageList); apiCountResult.countApiCoverage(countResultByApiCoverageList);
long allCount = apiCountResult.getCoveredCount() + apiCountResult.getNotCoveredCount();
if (allCount != 0) { if (allCount != 0) {
float coveredRateNumber = (float) apiCountResult.getCoveredCount() * 100 / allCount; float coveredRateNumber = (float) apiCountResult.getCoveredCount() * 100 / allCount;
DecimalFormat df = new DecimalFormat("0.0"); DecimalFormat df = new DecimalFormat("0.0");
@ -183,9 +183,8 @@ public class ApiHomeController {
} }
try { try {
//计算用例的通过率和执行率 //计算用例的通过率和执行率
List<ExecuteResultCountDTO> apiCaseExecResultList = apiTestCaseService.selectExecuteResultByProjectId(apiCountResult.getTotal(), projectId, versionId); List<ExecuteResultCountDTO> apiCaseExecResultList = apiTestCaseService.selectExecuteResultByProjectId(allCount, projectId, versionId);
apiCountResult.countApiCaseRunResult(apiCaseExecResultList); apiCountResult.countApiCaseRunResult(apiCaseExecResultList);
long allCount = apiCountResult.getExecutedCount() + apiCountResult.getNotExecutedCount();
if (apiCountResult.getExecutedCount() > 0) { if (apiCountResult.getExecutedCount() > 0) {
//通过率 //通过率
float coveredRateNumber = (float) apiCountResult.getPassCount() * 100 / allCount; float coveredRateNumber = (float) apiCountResult.getPassCount() * 100 / allCount;

View File

@ -631,6 +631,10 @@ public class ApiTestCaseService {
return extApiTestCaseMapper.countProtocolByProjectID(projectId, versionId); return extApiTestCaseMapper.countProtocolByProjectID(projectId, versionId);
} }
public long countByProjectID(String projectId, String versionId) {
return extApiTestCaseMapper.countByProjectID(projectId, versionId);
}
public long countByProjectIDAndCreateInThisWeek(String projectId, String versionId) { public long countByProjectIDAndCreateInThisWeek(String projectId, String versionId) {
Map<String, Date> startAndEndDateInWeek = DateUtils.getWeedFirstTimeAndLastTime(new Date()); Map<String, Date> startAndEndDateInWeek = DateUtils.getWeedFirstTimeAndLastTime(new Date());