fix(接口测试): 增加百分比计算工具类的健壮性
This commit is contained in:
parent
6c9cccf0ab
commit
cc5a660929
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue