fix(测试跟踪): 修复测试计划用例数错误的问题
This commit is contained in:
parent
e740d55ac8
commit
b92364ff6f
|
@ -372,20 +372,20 @@
|
|||
<select id="getTestPlanCase" resultType="int">
|
||||
select count(s)
|
||||
from (
|
||||
select id as s
|
||||
from test_plan_test_case tptc
|
||||
select tptc.id as s
|
||||
from test_plan_test_case tptc join test_case on tptc.case_id = test_case.id
|
||||
where tptc.plan_id = #{planId}
|
||||
union all
|
||||
select id as s
|
||||
from test_plan_api_scenario tpas
|
||||
where tpas.test_plan_id = #{planId}
|
||||
select tpas.id as s
|
||||
from test_plan_api_scenario tpas join api_scenario on tpas.api_scenario_id = api_scenario.id
|
||||
where tpas.test_plan_id = #{planId} and api_scenario.status != 'Trash'
|
||||
union all
|
||||
select id as s
|
||||
from test_plan_api_case tpac
|
||||
select tpac.id as s
|
||||
from test_plan_api_case tpac join api_test_case on tpac.api_case_id = api_test_case.id
|
||||
where tpac.test_plan_id = #{planId}
|
||||
union all
|
||||
select id as s
|
||||
from test_plan_load_case tplc
|
||||
select tplc.id as s
|
||||
from test_plan_load_case tplc join load_test on tplc.load_case_id = load_test.id
|
||||
where tplc.test_plan_id = #{planId}
|
||||
) as temp
|
||||
</select>
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
package io.metersphere.track.service;
|
||||
|
||||
import io.metersphere.api.dto.automation.ScenarioStatus;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
|
||||
import io.metersphere.commons.constants.TestPlanTestCaseStatus;
|
||||
import io.metersphere.commons.utils.DateUtils;
|
||||
import io.metersphere.commons.utils.MathUtils;
|
||||
import io.metersphere.performance.base.ChartsData;
|
||||
import io.metersphere.track.dto.TestPlanDTOWithMetric;
|
||||
import io.metersphere.track.response.BugStatustics;
|
||||
import io.metersphere.track.response.TestPlanBugCount;
|
||||
import io.metersphere.track.response.TrackCountResult;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.annotation.Resource;
|
||||
|
@ -28,13 +34,13 @@ public class TrackService {
|
|||
@Resource
|
||||
private TestPlanMapper testPlanMapper;
|
||||
@Resource
|
||||
private TestPlanTestCaseMapper testPlanTestCaseMapper;
|
||||
private ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper;
|
||||
@Resource
|
||||
private TestPlanLoadCaseMapper testPlanLoadCaseMapper;
|
||||
private TestPlanApiCaseService testPlanApiCaseService;
|
||||
@Resource
|
||||
private TestPlanApiCaseMapper testPlanApiCaseMapper;
|
||||
private TestPlanScenarioCaseService testPlanScenarioCaseService;
|
||||
@Resource
|
||||
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
|
||||
private TestPlanLoadCaseService testPlanLoadCaseService;
|
||||
|
||||
public List<TrackCountResult> countPriority(String projectId) {
|
||||
return extTestCaseMapper.countPriority(projectId);
|
||||
|
@ -132,11 +138,13 @@ public class TrackService {
|
|||
|
||||
int planBugSize = getPlanBugSize(plan.getId());
|
||||
testPlanBug.setBugSize(planBugSize);
|
||||
testPlanBug.setPassRage(getPlanPassRage(plan.getId(), planCaseSize));
|
||||
double planPassRage = getPlanPassRage(plan.getId());
|
||||
testPlanBug.setPassRage(planPassRage + "%");
|
||||
list.add(testPlanBug);
|
||||
|
||||
totalBugSize += planBugSize;
|
||||
totalCaseSize += planCaseSize;
|
||||
|
||||
}
|
||||
|
||||
bugStatustics.setList(list);
|
||||
|
@ -156,13 +164,52 @@ public class TrackService {
|
|||
return extTestCaseMapper.getTestPlanBug(planId);
|
||||
}
|
||||
|
||||
private String getPlanPassRage(String planId, int totalSize) {
|
||||
if (totalSize == 0) {
|
||||
return "-";
|
||||
}
|
||||
int passSize = extTestCaseMapper.getTestPlanPassCase(planId);
|
||||
float rage = (float) passSize * 100 / totalSize;
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
return df.format(rage) + "%";
|
||||
private double getPlanPassRage(String planId) {
|
||||
TestPlanDTOWithMetric testPlan = new TestPlanDTOWithMetric();
|
||||
testPlan.setTested(0);
|
||||
testPlan.setPassed(0);
|
||||
testPlan.setTotal(0);
|
||||
|
||||
List<String> functionalExecResults = extTestPlanTestCaseMapper.getExecResultByPlanId(planId);
|
||||
functionalExecResults.forEach(item -> {
|
||||
if (!StringUtils.equals(item, TestPlanTestCaseStatus.Prepare.name())
|
||||
&& !StringUtils.equals(item, TestPlanTestCaseStatus.Underway.name())) {
|
||||
testPlan.setTested(testPlan.getTested() + 1);
|
||||
if (StringUtils.equals(item, TestPlanTestCaseStatus.Pass.name())) {
|
||||
testPlan.setPassed(testPlan.getPassed() + 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
List<String> apiExecResults = testPlanApiCaseService.getExecResultByPlanId(planId);
|
||||
apiExecResults.forEach(item -> {
|
||||
if (StringUtils.isNotBlank(item)) {
|
||||
testPlan.setTested(testPlan.getTested() + 1);
|
||||
if (StringUtils.equals(item, "success")) {
|
||||
testPlan.setPassed(testPlan.getPassed() + 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
List<String> scenarioExecResults = testPlanScenarioCaseService.getExecResultByPlanId(planId);
|
||||
scenarioExecResults.forEach(item -> {
|
||||
if (StringUtils.isNotBlank(item)) {
|
||||
testPlan.setTested(testPlan.getTested() + 1);
|
||||
if (StringUtils.equals(item, ScenarioStatus.Success.name())) {
|
||||
testPlan.setPassed(testPlan.getPassed() + 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
List<String> loadResults = testPlanLoadCaseService.getStatus(planId);
|
||||
loadResults.forEach(item -> {
|
||||
if (StringUtils.isNotBlank(item)) {
|
||||
testPlan.setTested(testPlan.getTested() + 1);
|
||||
if (StringUtils.equals(item, "success")) {
|
||||
testPlan.setPassed(testPlan.getPassed() + 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
return MathUtils.getPercentWithDecimal(testPlan.getTested() == 0 ? 0 : testPlan.getPassed() * 1.0 / testPlan.getTested());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue