We are using utbot-cli to generate unit tests for some open source projects. However, the test generation failed for bunch of applications due to:
java.lang.IllegalStateException: Error: Cannot find the target class in the classpath
run mvn dependency:build-classpath --define mdep.outputFile=/tmp/classpath.txt to store dependency classpath into a file.
run mvn compile to compile the code (use Java 8)
compile UTBotJava and get utbot-cli.jar
Run bunchGenerate command through code like
java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.ref=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED --add-opens=java.base/jdk.internal.icu.util=ALL-UNNAMED --add-opens=java.base/sun.security.util=ALL-UNNAMED --add-opens=java.logging/java.util.logging=ALL-UNNAMED -jar /<Relative Path to utbot-cli>/utbot-cli.jar bunchGenerate --test-framework junit5 --classpath /<Relative path to fuzzler >/src/target/classes --classpathFile /tmp/classpath.txt --output <Any output path>
Expected behavior
Some tests should be generated
Actual behavior
It will fail and throw exception
Visual proofs (screenshots, logs, images)
java.lang.IllegalStateException: Error: Cannot find the target class in the classpath
--
2030 | at org.utbot.cli.BunchTestGeneratorCommand.generateTestsForClass(BunchTestGeneratorCommand.kt:88)
2031 | at org.utbot.cli.BunchTestGeneratorCommand.run(BunchTestGeneratorCommand.kt:78)
2032 | at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:204)
2033 | at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:213)
2034 | at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:17)
2035 | at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:396)
2036 | at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:393)
2037 | at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:411)
2038 | at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:436)
2039 | at org.utbot.cli.ApplicationKt.main(Application.kt:31)
Description
We are using utbot-cli to generate unit tests for some open source projects. However, the test generation failed for bunch of applications due to:
java.lang.IllegalStateException: Error: Cannot find the target class in the classpath
This happens when trying to load class member of some classes. The current classFqnToPath function (https://github.com/UnitTestBot/UTBotJava/blob/main/utbot-core/src/main/kotlin/org/utbot/common/PathUtil.kt#L85) simply replaced '.' with '/' which doesn't work for this case.
To Reproduce
Steps to reproduce the behavior:
mvn dependency:build-classpath --define mdep.outputFile=/tmp/classpath.txt
to store dependency classpath into a file.mvn compile
to compile the code (use Java 8)java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.ref=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED --add-opens=java.base/jdk.internal.icu.util=ALL-UNNAMED --add-opens=java.base/sun.security.util=ALL-UNNAMED --add-opens=java.logging/java.util.logging=ALL-UNNAMED -jar /<Relative Path to utbot-cli>/utbot-cli.jar bunchGenerate --test-framework junit5 --classpath /<Relative path to fuzzler >/src/target/classes --classpathFile /tmp/classpath.txt --output <Any output path>
Expected behavior
Some tests should be generated
Actual behavior
It will fail and throw exception
Visual proofs (screenshots, logs, images)
Environment
Additional context
Add any other context about the problem here.