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)); } }