I am trying to use Randoop (by following Randoop Manual) to generate test cases based on pre- and post- conditions specification stored in a JSON file.
Target program is the following (buggy) Java method.
package com.example.math;
public class Math {
    /*Expected Behavior:
          Given upperBound >= 0, the method returns
               1 + 2 + ... + upperBound                 
      But This method is buggy and works only on
      inputs with odd value, e.g. for upperBound == 4,
      the method returns 1 + 2 + 3 + 4 + 1 instead of
      1 + 2 + 3 + 4                                   */
    public static int sum(int upperBound) {
        int s = 0;
        for (int i = 0; i <= upperBound; i++) {
            s += i;
        }
        if (upperBound % 2 == 0) {// <--------- BUG!
            s++;                  // <--------- BUG!
        }                         // <--------- BUG!
        return s;
    }
}
And I use the following JSON file to specify the desired behavior of the method:
[
  {
    "operation": {
      "classname": "com.example.math.Math",
      "name": "sum",
      "parameterTypes": [ "int" ]
    },
    "identifiers": {
      "parameters": [ "upperBound" ],
      "returnName": "res"
    },
    "post": [
      {
        "property": {
          "condition": "res == upperBound * (upperBound + 1) / 2",
          "description": ""
        },
        "description": "",
        "guard": {
          "condition": "true",
          "description": ""
        }
      }
    ],
    "pre": [
      {
        "description": "upperBound must be non-negative",
        "guard": {
          "condition": "upperBound >= 0",
          "description": "upperBound must be non-negative"
        }
      }
    ]
  }
]
I compile the program, and run the following command to apply Randoop so as to generate test cases based on the correctness specification:
java -cp my-classpath:$RANDOOP_JAR randoop.main.Main gentests --testclass=com.example.math.Math --output-limit=200 --specifications=spec.json
Where spec.json is the JSON file containing the above specification for method contracts. I have got two questions:
- Why does not changing --output-limitchange the number of generated test cases? For sufficiently large numbers, it seems that I always get only 8 regression test cases two of which checking the methodgetClassdoes not returnnullvalue (even though that is not part of my specification). Please kindly let me know how I can generate more regression test cases. Am I missing a command-line option?
- It seems that Randoop does not consult the specification inside spec.jsonwhen it tries to generate error-revealing test cases. Can we make Randoop generate error-revealing test cases on every input that violates the provided post-condition?
Thank you.
 
    