From cc5a6609293d0cddec8f57d52b05fddeaa89f023 Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Fri, 15 Nov 2024 10:36:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BE=E5=88=86=E6=AF=94=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=E7=9A=84=E5=81=A5=E5=A3=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/metersphere/sdk/util/CalculateUtils.java | 3 +++ .../java/io/metersphere/api/controller/ApiCalculateTest.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/CalculateUtils.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/CalculateUtils.java index 429ec0b0cc..b43c66d8cc 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/CalculateUtils.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/CalculateUtils.java @@ -6,6 +6,9 @@ public class CalculateUtils { // 报告所需的百分比计算 public static String reportPercentage(int numerator, int denominator) { + if (denominator == 0) { + return "0.00%"; + } DecimalFormat rateFormat = new DecimalFormat("#0.00"); rateFormat.setMinimumFractionDigits(2); rateFormat.setMaximumFractionDigits(2); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiCalculateTest.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiCalculateTest.java index 3abec57904..080d24c9a9 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiCalculateTest.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiCalculateTest.java @@ -232,6 +232,8 @@ public class ApiCalculateTest extends BaseTest { Assertions.assertEquals(apiCoverageDTO.getCoverWithApiDefinition(), 10); Assertions.assertEquals(apiCoverageDTO.getUnCoverWithApiDefinition(), 10); Assertions.assertEquals(apiCoverageDTO.getApiCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiDefinition(), apiCoverageDTO.getAllApiCount())); + + Assertions.assertEquals("0.00%", CalculateUtils.reportPercentage(0, 0)); } }