0

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)

  • Welcome to Stackoverflow Nikolay. Can you share what is output for b==1 and 5? – yılmaz Apr 16 '19 at 20:17
  • I'm implying a developer of Calculator.div(a, b) hasn't handled correctly the corner cases when argument b is 1 or 5 which leads to division by 0 and unexpected ArithmeticException. One of the case (for b==1) is caught by Evosuite and that's really great but wanted to catch all the tricky cases. – Nikolay Orlov Apr 16 '19 at 20:28
  • what happened for b==5? – yılmaz Apr 17 '19 at 11:15

0 Answers0