1

My objective is to generate very basic unit tests for a lot of legacy code we are migrating to a new platform. (I know unit tests are not useful this way, but sometimes it happens). We are only blocked for covering percentage so it is good to go with basic tests in the methods we need, so going with an automatically generated tests will be the most efficient strategy.

I found RANDOOP https://randoop.github.io/randoop/ and start trying to make it work. However I found a problem, which in part is due to my almost zero knowledge of java ( I did something similar in .net with just a few clicks and in less than 4 hours).

I´m following official manual here https://randoop.github.io/randoop/manual/index.html#getting_randoop and the video of this guy who just makes it work https://www.youtube.com/watch?v=nPdb-72-EJY.

The Problem

Plain words the problem is the following error when I run this command

java -classpath 'C:\randoop-4.2.1\bin;C:\randoop-4.2.1\randoop-all-4.2.1.jar' randoop.main.Main gentests --testclass=ClassName

> Throwable thrown while handling command:
> java.lang.IllegalStateException: Cannot find the Java compiler. Check
> that classpath includes tools.jar java.lang.IllegalStateException:
> Cannot find the Java compiler. Check that classpath includes tools.jar
>         at randoop.compile.SequenceCompiler.<init>(SequenceCompiler.java:64)
>         at randoop.compile.SequenceCompiler.<init>(SequenceCompiler.java:48)
>         at randoop.condition.SpecificationCollection.<init>(SpecificationCollection.java:82)
>         at randoop.condition.SpecificationCollection.create(SpecificationCollection.java:102)
>         at randoop.main.GenTests.handle(GenTests.java:279)
>         at randoop.main.Main.nonStaticMain(Main.java:66)
>         at randoop.main.Main.main(Main.java:30)
> 
> Randoop failed. No sequences generated.

what is this above?

I run the command from console placed at the bin folder of randoop "installation" folder.

C:\randoop-4.2.1\bin is the folder where I unzipped Randoop download. Some weird thing is that none of the Randoop version downloads contains the bin folder, so I created it arbitrarily. I don't know if that is right or wrong, but I just did it.

At the beginning the video runs the following command, which is really basic and it worked ok on my system.

java -classpath .\randoop-4.2.1\randoop-all-4.2.1.jar randoop.main.Main help gentests 

There is also a text file named myclasslist I don't understand why this guys never talk about. I don't have it.

I have Java 8 installed at c:\program files\jdk1.8.0_231and the Paths and environment variables are set like this.

Environment variables

EDIT

In the video, the guy has the .java file in the randoop root folder. I don´t since I have a real project in intellij. i just found the classs file and copied it to bin folder.

Ricker Silva
  • 1,137
  • 4
  • 17
  • 37
  • Did you try to add `c:\program files\jdk1.8.0_231\lib\tools.jar` in `-classpath` list? – CrazyCoder Jan 10 '20 at 23:18
  • No, how can i do that? I don´t even knew there was a classpath list – Ricker Silva Jan 10 '20 at 23:43
  • `java -classpath 'c:\program files\jdk1.8.0_231\lib\tools.jar;C:\randoop-4.2.1\bin;C:\randoop-4.2.1\randoop-all-4.2.1.jar' randoop.main.Main gentests --testclass=ClassName` – CrazyCoder Jan 10 '20 at 23:44
  • I did it like this, slightly different java -classpath 'C:\randoop-4.2.1\bin;C:\randoop-4.2.1\randoop-all-4.2.1.jar;C:\Program Files\Java\jdk1.8.0_231\lib\tools.jar' randoop.main.Main gentests --testclass=ClassName' but still throws the same error – Ricker Silva Jan 10 '20 at 23:47
  • Also changed the order of the classpath items and put tools.jar first, but the same error – Ricker Silva Jan 10 '20 at 23:50
  • Looks like https://github.com/randoop/randoop/issues/176. – CrazyCoder Jan 10 '20 at 23:52
  • Yes I checked that. I also included my paths configurations in the question – Ricker Silva Jan 10 '20 at 23:55
  • Your screenshot doesn't show System PATH environment variables. Use http://www.rapidee.com/ to double check the actual PATH. It may point to JRE instead of the JDK and System PATH has priority over the User PATH. Try running with `"c:\program files\jdk1.8.0_231\bin\java.exe" -classpath 'C:\randoop-4.2.1\bin;C:\randoop-4.2.1\randoop-all-4.2.1.jar' randoop.main.Main gentests --testclass=ClassName`. If it works, the issue is that default `java.exe` in your PATH is from JRE not from JDK. See the related answer for JDK PATH configuration: https://stackoverflow.com/a/58125957/104891. – CrazyCoder Jan 10 '20 at 23:57
  • This error is mentioned in the [Randoop Manual](https://randoop.github.io/randoop/manual/#cannot-find-main). Did you try the suggestions there? – mernst Jan 11 '20 at 18:33
  • Thank you guys, I double checked and corrected the environment variables pointing to jre instead of jdk. Sad news is I still can not run randoop. I think this question is misleading since I followed a mixture of tutorials and maybe the error is not eexactly this. I posted the details of the problems here https://github.com/randoop/randoop/issues/644 – Ricker Silva Jan 13 '20 at 21:25
  • @RickerSilva it's vice versa, you need JDK, not JRE. The rest of the issue is with the incorrect `java` command line syntax and not understanding what is `-classpath`. – CrazyCoder Jan 14 '20 at 00:27
  • @RickerSilva did my answer help to resolve the original issue with the JDK vs JRE and setting the classpath for the tool? I've also responded to your question here: https://github.com/randoop/randoop/issues/644 . – CrazyCoder Jan 22 '20 at 20:50

1 Answers1

0

Your screenshot doesn't show System PATH environment variable.

Double check the actual PATH. It may point to JRE instead of the JDK and the System PATH has priority over the User PATH.

Randoop requires JDK to work, not JRE.

Try running:

"c:\program files\jdk1.8.0_231\bin\java.exe" -classpath 'C:\randoop-4.2.1\bin;C:\randoop-4.2.1\randoop-all-4.2.1.jar' randoop.main.Main gentests --testclass=ClassName

If it works, the issue is that default java.exe in your PATH is from JRE not from JDK.

Note that -classpath argument points to the jars or the directories with .class files, not to the individual .class files. See the documentation.

Above command should work if your ClassName.class file is in C:\randoop-4.2.1\bin.

See the related answer for JDK PATH configuration.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904