This question already has answers here:
How do I resolve ClassNotFoundException?

(20个答案)


3个月前关闭。





我试图为基于Maven的Java应用程序运行Randoop。
该项目已通过cmd通过成功编译

G:\ javapplic \ a12> mvn编译

我要在其上创建测试的Java文件位于:
G:\ javapplic \ a12 \ src \ main \ java \ org \ jaffa \ datatypes \ configurer

我使用randoop生成存在于文件夹中的类:
G:\ javapplic \ a12 \ target \ classes \ org \ jaffa \ datatypes \ configurer

因此,在cmd中,我使用以下代码生成测试用例:

java -Xmx3000m -classpath G:\javapplic\a12\target\classes\org\jaffa\datatypes;G:\New\randoop-all-4.2.2.jar randoop.main.Main gentests --testclass=org.jaffa.datatypes.configurer.MybatisConfigurer


enter image description here
这是当前课程的路径

因此,在运行上述cmd命令后,出现以下错误:

    G:\javapplic\a12>java -Xmx3000m -classpath G:\javapplic\a12\target\classes\org\jaffa\datatypes;G:\New\randoop-all-4.2.2.jar randoop.main.Main gentests --testclass=org.jaffa.datatypes.configurer.MybatisConfigurer
Randoop for Java version "4.2.2, branch master, commit 4f20da2, 2020-02-29".
Unable to load class "org.jaffa.datatypes.configurer.MybatisConfigurer" due to exception: java.lang.ClassNotFoundException: org.jaffa.datatypes.configurer.MybatisConfigurerWill explore 0 out of 1 classes
There are no operations to test. Exiting.
Model with hashcode 1846896625:
  classTypes = [java.lang.Object]
  inputTypes = []
  coveredClassesGoal = []
  classLiteralMap = {}
  annotatedTestValues = []
  contracts = ContractSet[size=12]
  arity 1: [randoop.contract.EqualsReflexive@5cb9f472, randoop.contract.EqualsToNullRetFalse@cb644e, randoop.contract.EqualsReturnsNormally@13805618, randoop.contract.CompareToReflexive@56ef9176, randoop.contract.SizeToArrayLength@4566e5bd]
  arity 2: [randoop.contract.EqualsSymmetric@1ed4004b, randoop.contract.EqualsHashcode@ff5b51f, randoop.contract.CompareToAntiSymmetric@25bbe1b6, randoop.contract.CompareToEquals@5702b3b1]
  arity 3: [randoop.contract.EqualsTransitive@69ea3742, randoop.contract.CompareToSubs@4b952a2d, randoop.contract.CompareToTransitive@3159c4b8]

  omitMethods = [^org.apache.commons.math3.analysis.differentiation., ^org.apache.commons.math3.analysis.integration., \bensuresCapacity\b, ^com.google.common.collect.Iterators.cycle\(, ^org.apache.commons.math4.genetics.GeneticAlgorithm.getRandomGenerator\(\)$, ^org.apache.commons.math4.util.FastMath.random\(\)$, ^java\.util\.Date\.<init>\(\)$, ^java\.io\.File\.listFiles\(\)$, ^java\.io\.File\.listFiles\(java\.io\.FileFilter\)$, ^java\.io\.File\.listFiles\(java\.io\.FilenameFilter\)$, ^java\.io\.File\.listRoots\(\)$, ^java\.io\.File\.list\(\)$, ^java\.io\.File\.list\(java\.io\.FilenameFilter\)$, ^java\.lang\.Class\.getSigners\(\)$, ^java\.lang\.Object\.hashCode\(\)$, ^java\.lang\.String\.hashCode\(\)$, ^java\.lang\.System\.clearProperty\(java\.lang\.String\)$, ^java\.lang\.System\.console\(\)$, ^java\.lang\.System\.currentTimeMillis\(\)$, ^java\.lang\.System\.getProperties\(\)$, ^java\.lang\.System\.getProperty\(java\.lang\.String, java\.lang\.String\)$, ^java\.lang\.System\.getProperty\(java\.lang\.String\)$, ^java\.lang\.System\.getSecurityManager\(\)$, ^java\.lang\.System\.getenv\(\)$, ^java\.lang\.System\.getenv\(java\.lang\.String\)$, ^java\.lang\.System\.identityHashCode\(java\.lang\.Object\)$, ^java\.lang\.System\.inheritedChannel\(\)$, ^java\.lang\.System\.mapLibraryName\(java\.lang\.String\)$, ^java\.lang\.System\.nanoTime\(\)$, ^java\.lang\.System\.setProperty\(java\.lang\.String, java\.lang\.String\)$, ^java\.lang\.reflect\.Method\.hashCode\(\)$, ^java\.text\.BreakIterator\.getAvailableLocales\(\)$, ^java\.util\.AbstractList\.hashCode\(\)$, ^java\.util\.AbstractSet\.hashCode\(\)$, ^java\.util\.Arrays\.deepHashCode\(java\.lang\.Object\[\]\)$, ^java\.util\.Arrays\.hashCode\(boolean\[\]\)$, ^java\.util\.Arrays\.hashCode\(byte\[\]\)$, ^java\.util\.Arrays\.hashCode\(char\[\]\)$, ^java\.util\.Arrays\.hashCode\(double\[\]\)$, ^java\.util\.Arrays\.hashCode\(float\[\]\)$, ^java\.util\.Arrays\.hashCode\(int\[\]\)$, ^java\.util\.Arrays\.hashCode\(java\.lang\.Object\[\]\)$, ^java\.util\.Arrays\.hashCode\(long\[\]\)$, ^java\.util\.Arrays\.hashCode\(short\[\]\)$, ^java\.util\.Collection\.hashCode\(\)$, ^java\.util\.Collections\.shuffle\(java\.util\.List\)$, ^java\.util\.Comparator\.compare\(java\.lang\.Object, java\.lang\.Object\)$, ^java\.util\.List\.hashCode\(\)$, ^java\.util\.Random\.<init>\(\)$, ^java\.util\.Set\.hashCode\(\)$]
Operations:
  java.lang.Object.<init> : () -> java.lang.Object


因此,如果有人知道让Randoop在Maven项目上工作的解决方法,请告诉我

最佳答案

这个问题已经有答案here。我将在此处重复回答,但以后请一次在一个论坛中提问。

这个问题与Maven无关。

问题的答案在您提供的日志中。您需要修复您的类路径。

您的Randoop调用仅指定一个要测试的类:

--testclass=org.jaffa.datatypes.configurer.MybatisConfigurer

但是,在类路径中找不到该类:

Unable to load class "org.jaffa.datatypes.configurer.MybatisConfigurer" due to exception: java.lang.ClassNotFoundException: org.jaffa.datatypes.configurer.MybatisConfigurer


因此,Randoop尝试测试0个类:

Will explore 0 out of 1 classes

它无法为这0个类中的任何一个创建测试,因此退出:

There are no operations to test. Exiting.

如果修复了类路径,则可以运行Randoop。

07-25 23:29