java.lang.IllegalStateException trying to generate unit tests with randoop

784 Views Asked by At

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.

1

There are 1 best solutions below

0
CrazyCoder On

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.