考虑以下代码:
@Test
public final void testIsUnitInvalidSadCase() {
boolean expectedResult = false;
boolean actualResult = false;
double invalidUnit = 0.0;
testFuelUnitValidator =
new FuelUnitValidator(
defaultTimestamp,
defaultFluids,
invalidUnit);
actualResult = testFuelUnitValidator.isUnitInvalid();
assertThat(actualResult, is(equalTo(expectedResult)));
}
@Test
public final void testIsUnitInvalidHappyCase() {
boolean expectedResult = false;
boolean actualResult = true;
double invalidUnit = 0.02;
testFuelUnitValidator =
new FuelUnitValidator(
defaultTimestamp,
defaultFluids,
invalidUnit);
actualResult = testFuelUnitValidator.isUnitInvalid();
assertThat(actualResult, is(equalTo(expectedResult)));
}
这是方法:
public boolean isUnitInvalid() {
if (Math.abs(unit) < 0.0) {
return true;
}
return false;
}
当我将行更改为if (Math.abs(smu) <= 0.01)
和测试类作为boolean expectedResult = true;
第一个测试时,maven 构建得很好。但是当我尝试使用上面的代码构建时,maven 会抛出一个错误:
[ERROR] *className failed check. Branch coverage rate of 95.8% is below 100.0%
*className failed check. Line coverage rate of 97.8% is below 100.0%