fix(接口测试): 增加百分比计算工具类的健壮性

This commit is contained in:
Jianguo-Genius 2024-11-15 10:36:04 +08:00 committed by 建国
parent 6c9cccf0ab
commit cc5a660929
2 changed files with 5 additions and 0 deletions

View File

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

View File

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