From 16f9b1eb3de9a03c933cbcee4c3dc6b77f7078bc Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 16 Oct 2023 17:06:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=8E=87=E7=B2=BE=E5=BA=A6=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E5=88=B0=E4=B8=A4=E4=BD=8D=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1031001 --user=宋天阳 【测试跟踪】测试计划列表通过率未实现保留两位小数 https://www.tapd.cn/55049933/s/1426628 --- .../plan/service/TestPlanService.java | 89 +++++++++++-------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 3421bac3b7..b0045531a0 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -165,6 +165,35 @@ public class TestPlanService { @Resource private BaseTestResourcePoolService baseTestResourcePoolService; + private static void buildCaseIdList + (List list, List apiCaseIds, List scenarioIds, List performanceIds, List uiScenarioIds) { + for (TestCaseTest l : list) { + if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.performance.name())) { + performanceIds.add(l.getTestId()); + } + if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.testcase.name())) { + apiCaseIds.add(l.getTestId()); + } + if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.automation.name())) { + scenarioIds.add(l.getTestId()); + } + if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.uiAutomation.name())) { + uiScenarioIds.add(l.getTestId()); + } + } + } + + //获取下次执行时间(getFireTimeAfter,也可以下下次...) + private static long getNextTriggerTime(String cron) { + if (!CronExpression.isValidExpression(cron)) { + return 0; + } + CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("Calculate Date").withSchedule(CronScheduleBuilder.cronSchedule(cron)).build(); + Date time0 = trigger.getStartTime(); + Date time1 = trigger.getFireTimeAfter(time0); + return time1 == null ? 0 : time1.getTime(); + } + public TestPlan addTestPlan(AddTestPlanRequest testPlan) { if (getTestPlanByName(testPlan.getName()).size() > 0) { MSException.throwException(Translator.get("plan_name_already_exists")); @@ -428,6 +457,10 @@ public class TestPlanService { public List calcTestPlanRateByIdList(List testPlanIdList) { List returnList = new ArrayList<>(); + DecimalFormat rateFormat = new DecimalFormat("#0.00"); + rateFormat.setMinimumFractionDigits(2); + rateFormat.setMaximumFractionDigits(2); + for (String testPlanId : testPlanIdList) { TestPlanDTOWithMetric returnMetric = new TestPlanDTOWithMetric(); returnMetric.setId(testPlanId); @@ -448,7 +481,7 @@ public class TestPlanService { } } } - returnMetric.setTotal(returnMetric.getTotal() + functionalExecTotal); + returnMetric.setTotal(functionalExecTotal); Set serviceIdSet = DiscoveryUtil.getServiceIdSet(); if (serviceIdSet.contains(MicroServiceName.API_TEST)) { @@ -462,8 +495,26 @@ public class TestPlanService { calcExecResultStatus(testPlanId, returnMetric, planTestPlanUiScenarioCaseService::getExecResultByPlanId); } - returnMetric.setPassRate(MathUtils.getPercentWithDecimal(returnMetric.getTested() == 0 ? 0 : returnMetric.getPassed() * 1.0 / returnMetric.getTotal())); - returnMetric.setTestRate(MathUtils.getPercentWithDecimal(returnMetric.getTotal() == 0 ? 0 : returnMetric.getTested() * 1.0 / returnMetric.getTotal())); + if (returnMetric.getTotal() > 0) { + int passCount = returnMetric.getPassed(); + double passRate = Double.parseDouble(rateFormat.format((double) passCount * 100 / (double) returnMetric.getTotal())); + if (passRate == 100 && passCount < returnMetric.getTotal()) { + returnMetric.setPassRate(0.9999); + } else { + returnMetric.setPassRate(passRate); + } + + int testCount = returnMetric.getTested(); + double testRate = Double.parseDouble(rateFormat.format((double) testCount * 100 / (double) returnMetric.getTotal())); + if (testRate == 100 && testCount < returnMetric.getTotal()) { + returnMetric.setTestRate(0.9999); + } else { + returnMetric.setTestRate(testRate); + } + } else { + returnMetric.setPassRate(0.00); + returnMetric.setTestRate(0.00); + } returnList.add(returnMetric); } return returnList; @@ -738,7 +789,6 @@ public class TestPlanService { } } - public void caseTestRelevance(PlanCaseRelevanceRequest request, List testCaseIds) { //同步添加关联的接口和测试用例 if (!request.getChecked()) { @@ -781,24 +831,6 @@ public class TestPlanService { } } - private static void buildCaseIdList - (List list, List apiCaseIds, List scenarioIds, List performanceIds, List uiScenarioIds) { - for (TestCaseTest l : list) { - if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.performance.name())) { - performanceIds.add(l.getTestId()); - } - if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.testcase.name())) { - apiCaseIds.add(l.getTestId()); - } - if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.automation.name())) { - scenarioIds.add(l.getTestId()); - } - if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.uiAutomation.name())) { - uiScenarioIds.add(l.getTestId()); - } - } - } - private List getDefaultOrders() { List orderRequests = new ArrayList<>(); OrderRequest orderRequest = new OrderRequest(); @@ -1235,7 +1267,6 @@ public class TestPlanService { return replaceSharReport(microServices); } - /** * 获取微服务信息,替换前端变量 * 实现跨服务访问报告 @@ -1603,7 +1634,6 @@ public class TestPlanService { return reportStruct; } - public TestPlanReportDataStruct buildPlanReport(String planId, boolean saveResponse) { TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(planId); @@ -2072,17 +2102,6 @@ public class TestPlanService { } - //获取下次执行时间(getFireTimeAfter,也可以下下次...) - private static long getNextTriggerTime(String cron) { - if (!CronExpression.isValidExpression(cron)) { - return 0; - } - CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("Calculate Date").withSchedule(CronScheduleBuilder.cronSchedule(cron)).build(); - Date time0 = trigger.getStartTime(); - Date time1 = trigger.getFireTimeAfter(time0); - return time1 == null ? 0 : time1.getTime(); - } - @MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN_SCHEDULE, type = OperLogConstants.UPDATE, title = "#request.name", beforeEvent = "#msClass.getLogDetails(#request.id)", content = "#msClass.getLogDetails(#request.id)", msClass = BaseScheduleService.class) public Schedule updateSchedule(Schedule request) {