dimanche 1 février 2015

Why is my branch coverage rate and line coverage rate failing?

Consider the following code:



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


This is the method:



public boolean isUnitInvalid() {
if (Math.abs(unit) < 0.0) {
return true;
}
return false;
}


When I change the line as if (Math.abs(smu) <= 0.01) and the test classes as boolean expectedResult = true; for the first test then the maven builds up fine. But when I try to build with above code, maven throws an error as: [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%


Aucun commentaire:

Enregistrer un commentaire