My sample target code to cover by tests looks like this :
public class Calculator {
public int div(final int a, final int b) {
if (b > 3) {
return a/(b-5);
} else {
return a/(b-1);
}
}
}
I'm expecting tests with argument b == 1
and b == 5
are generated to uncover all possible ArithmeticException
cases. But just this option uncovering only 1 ArithmeticException
case is provided:
@Test(timeout = 4000)
public void test3() throws Throwable {
Calculator calculator0 = new Calculator();
// Undeclared exception!
try {
calculator0.div(2232, 1);
fail("Expecting exception: ArithmeticException");
} catch(ArithmeticException e) {
//
// / by zero
//
verifyException("hello.Calculator", e);
}
}
(other generated tests are: div(0, 3); div(-5, 0); div(5, 0); div(-635, 3661);
)
I've tried these run options for mvn but nothing helps: -Dsearch_budget=600 -DtimeInMinutesPerClass=15 -Dminimize=false -Dassertion_strategy=all
Is there a way to catch all the "tricky" test cases?
There are similar questions already:
Evosuite generates only a few test cases (no answer)
EvoSuite - Parameters For Getting Most Code Coverage (suggesting to use -Dsearch_budget
parameter which doesn't work out for my case)