下载:https://randoop.github.io/randoop/
打开github,搜索randoop,点release获得zip文件,解压缩,将测试类放到randoop的jar所在目录
编译测试类
错误信息
Cannot find the Java compiler. Check that classpath includes tools.jar
解决:将%JAVA_HOME%\lib\tools.jar文件复制到%JAVA_HOME%.\jre1.8.0_121\lib\目录下
生成测试用例
java -Xmx3000m -classpath .;randoop-all-4.1.0.jar;Test1 randoop.main.Main gentests --testclass=Test1 --output-limit=100
测试类加入对称性错误让randoop自动生成检测错误代码的测试用例:
public void setName(String name) {
if (this.name.equals(name) == name.equals(this.name))
;
else
this.name = name;
}
再次编译,生成测试用例:
将junit.jar和hamcrest-core.jar放入当前文件夹:
编译ErrorTest.java和运行检测错误的测试用例,结果提示代码中出错的具体方法:
java -classpath .;junit-4.12.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore ErrorTest
编译RegressionTest.java和运行回归测试:
java -classpath .;junit-4.12.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore RegressionTest