In this section, we evaluate Randoop with BugSwarm to test it test generation capability. We will use alibaba-fastjson2-15942144023 artifact to evaluate Randoop.
cd ~
wget https://github.com/randoop/randoop/releases/download/v4.3.2/randoop-all-4.3.2.jar
wget https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar
wget https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jarCopy files to bugswarm-sandbox directory
cp randoop-all-4.3.2.jar ~/bugswarm-sandbox
cp junit-4.13.2.jar ~/bugswarm-sandbox
cp hamcrest-core-1.3.jar ~/bugswarm-sandboxbugswarm run --image-tag alibaba-fastjson2-15942144023 --use-sandboxcd ~/
cp /bugswarm-sandbox/* ~/
Setup environment variable
ls
export RANDOOP_JAR="$(pwd)/randoop-all-4.3.2.jar"run_failed.shfind . -name "DateUtilsTestFormat.java"The file we are looking for is in the build/failed/alibaba/fastjson2/core directory. We can open the test file and go to line 150
sed -n 150p ./build/failed/alibaba/fastjson2/core/src/test/java/com/alibaba/fastjson2/util/DateUtilsTestFormat.javaFrom here, we know that there is a fault in the DateUtils.formatYMDHMS19 method. To verify this, we can use the BugSwarm dataset website.
Open https://www.bugswarm.org/dataset, under Image Tag, enter the artifact ID alibaba-fastjson2-15942144023, click the link under Diff URL.
Based on the diff, we can confirm that the developer fixed the bug by changing the formatYMDHMS19 method.
Now, let's locate this DateUtils file using the find command
find . -name "DateUtils.java"
less ./build/failed/alibaba/fastjson2/core/src/main/java/com/alibaba/fastjson2/util/DateUtils.javaWe can see the package is com.alibaba.fastjson2.util, we will need this when we run Randoop.
Save dependencies to the target directory
cd ./build/failed/alibaba/fastjson2/core/
mvn dependency:copy-dependenciesjava -Xmx3000m -classpath $RANDOOP_JAR:target/classes:target/dependency/* randoop.main.Main gentests --testclass=com.alibaba.fastjson2.util.DateUtils
less ErrorTest0.javaUnfortunately, none of the tests Randoop generated reveal the bug.
Copy JUnit to current directory
cp ~/junit-4.13.2.jar .
cp ~/hamcrest-core-1.3.jar .Compile test and code
javac -classpath .:junit-4.13.2.jar:hamcrest-core-1.3.jar:target/classes:target/dependency/* ErrorTest*.java -sourcepath .:target/classes:target/dependency/*Run test
java -classpath .:junit-4.13.2.jar:hamcrest-core-1.3.jar:target/classes:target/dependency/* org.junit.runner.JUnitCore ErrorTest