How to resolve Invisible class error in Randoop?

264 views Asked by At

I have a simple class in java conatining something like this

package 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;
    }
}

now for this I am trying to generate unit test case using randoop and the command which I am using here is given below and my Math.class file is in /home/niteshb/Downloads/randoop-4.2.6/Tests.class

java -cp /home/niteshb/Downloads/randoop-4.2.6:/home/niteshb/Downloads/randoop-4.2.6/randoop-all-4.2.6.jar randoop.main.Main gentests --testclass=Math --literals-file=CLASSES

here after execution I am getting error as

Cannot instantiate non-visible Math specified via --testclass or --classlist.

Will try to generate tests for 0 out of 1 classes.
You provided no methods to test, so no tests for them can be generated.

Additional diagnostis appear below.
Model with hashcode 1253946629:
  classTypes = [java.lang.Object]
  inputTypes = []
  coveredClassesGoal = []
  classLiteralMap = {}
  annotatedTestValues = []
  contracts = ContractSet[size=12]
    arity 1: [randoop.contract.EqualsReflexive@7ce6a65d, randoop.contract.EqualsToNullRetFalse@1500955a, randoop.contract.EqualsReturnsNormally@e874448, randoop.contract.CompareToReflexive@29b5cd00, randoop.contract.SizeToArrayLength@60285225]
    arity 2: [randoop.contract.EqualsSymmetric@7113b13f, randoop.contract.EqualsHashcode@45820e51, randoop.contract.CompareToAntiSymmetric@42d8062c, randoop.contract.CompareToEquals@6043cd28]
    arity 3: [randoop.contract.EqualsTransitive@cb51256, randoop.contract.CompareToSubs@59906517, randoop.contract.CompareToTransitive@5bfbf16f]
  omitMethods = [
    \bensuresCapacity\b
    ^\Qcom.google.common.collect.Iterators.cycle(
    ^\Qorg.apache.commons.math4.genetics.GeneticAlgorithm.getRandomGenerator()\E$
    ^\Qorg.apache.commons.math4.util.FastMath.random()\E$
    ^\Qjava.util.Date.<init>()\E$
    ^\Qorg.joda.time.DateTime.now()\E$
    ^\Qorg.joda.time.LocalDate.<init>\E$
    ^\Qnew org.joda.time.Partial.<init>()\E$
    ^\Qjava.io.File.list()\E$
    ^\Qjava.io.File.list(java.io.FilenameFilter)\E$
    ^\Qjava.io.File.listFiles()\E$
    ^\Qjava.io.File.listFiles(java.io.FileFilter)\E$
    ^\Qjava.io.File.listFiles(java.io.FilenameFilter)\E$
    ^\Qjava.io.File.listRoots()\E$
    ^\Qjava.lang.Class.getSigners()\E$
    ^\Qjava.lang.Object.hashCode()\E$
    ^\Qjava.lang.String.hashCode()\E$
    ^\Qjava.lang.System.clearProperty(java.lang.String)\E$
    ^\Qjava.lang.System.console()\E$
    ^\Qjava.lang.System.currentTimeMillis()\E$
    ^\Qjava.lang.System.getProperties()\E$
    ^\Qjava.lang.System.getProperty(java.lang.String)\E$
    ^\Qjava.lang.System.getProperty(java.lang.String, java.lang.String)\E$
    ^\Qjava.lang.System.getSecurityManager()\E$
    ^\Qjava.lang.System.getenv()\E$
    ^\Qjava.lang.System.getenv(java.lang.String)\E$
    ^\Qjava.lang.System.identityHashCode(java.lang.Object)\E$
    ^\Qjava.lang.System.inheritedChannel()\E$
    ^\Qjava.lang.System.mapLibraryName(java.lang.String)\E$
    ^\Qjava.lang.System.nanoTime()\E$
    ^\Qjava.lang.System.setProperty(java.lang.String, java.lang.String)\E$
    ^\Qjava.lang.reflect.Method.hashCode()\E$
    ^\Qjava.text.BreakIterator.getAvailableLocales()\E$
    ^\Qjava.util.AbstractList.hashCode()\E$
    ^\Qjava.util.AbstractSet.hashCode()\E$
    ^\Qjava.util.Arrays.deepHashCode(java.lang.Object[])\E$
    ^\Qjava.util.Arrays.hashCode(boolean[])\E$
    ^\Qjava.util.Arrays.hashCode(byte[])\E$
    ^\Qjava.util.Arrays.hashCode(char[])\E$
    ^\Qjava.util.Arrays.hashCode(double[])\E$
    ^\Qjava.util.Arrays.hashCode(float[])\E$
    ^\Qjava.util.Arrays.hashCode(int[])\E$
    ^\Qjava.util.Arrays.hashCode(java.lang.Object[])\E$
    ^\Qjava.util.Arrays.hashCode(long[])\E$
    ^\Qjava.util.Arrays.hashCode(short[])\E$
    ^\Qjava.util.Collection.hashCode()\E$
    ^\Qjava.util.Collections.shuffle(java.util.List)\E$
    ^\Qjava.util.Comparator.compare(java.lang.Object, java.lang.Object)\E$
    ^\Qjava.util.List.hashCode()\E$
    ^\Qjava.util.Random.<init>()\E$
    ^\Qjava.util.Set.hashCode()\E$
  ]
Operations: (1)
  java.lang.Object.<init> : () -> java.lang.Object

There are no methods for Randoop to test.  See diagnostics above.  Exiting.

can someone pls help me with this , I am stucked here for long time tried different things but didnt worked out ..

1

There are 1 answers

0
user15895291 On

Try something like this it worked

java -classpath /home/niteshb/Downloads/randoop-4.2.6:/home/niteshb/Downloads/randoop-4.2.6/randoop-all-4.2.6.jar randoop.main.Main gentests --testclass=math.Math --output-limit=10