EvoSuite - Automated Test Case Generation

EvoSuite is a tool that examines Java byte code and automatically creates a Junit test suite.

Download from here: http://www.st.cs.uni-saarland.de/evosuite/index.html

Use from command line as follows:
$ # create build/libs/RefactoringExperiment.jar
$ java -jar lib/evosuite-20110908.jar -setup build/libs/RefactoringExperiment.jar
$ java -jar lib/evosuite-20110908.jar -assertions -generateSuite

Evosuite works on bytecode, so the easiest way to use it is to create a jar containing all source code to be tested, then use that as part of the java command.

Here is a gradle task that first creates a jar containing everything in src/main/java, then runs setup and generateSuite.
apply plugin: 'java'
task evosuite (dependsOn: jar) << {
    ant {
  
        java(jar: evosuiteJar, fork:true) {
            arg(value: "-setup")
            arg(value: "build/libs/RefactoringExperiment.jar")
        }
  
        java(jar: evosuiteJar, fork:true) {
            arg(value: "-assertions")
            arg(value: "-generateSuite")
        }
    }
}
To run the setup and generateSuite tasks from a bash script, use the following snippet. The -mem parameter is not documented, and only available from evosuite-20110929.jar onwards. It specifies the amount of memory available for the the JVM that runs the test generation. Using -Xmx... has no effect on that JVM.
# EvoSuite setup
java -cp ~/lib/evosuite.jar de.unisb.cs.st.evosuite.EvoSuite -setup build/libs/$project.jar

# run with criterion branch
java -cp ~/lib/evosuite.jar de.unisb.cs.st.evosuite.EvoSuite -assertions -criterion branch -generateSuite -mem 3000

# run with criterion mutation
java -cp ~/lib/evosuite.jar de.unisb.cs.st.evosuite.EvoSuite -assertions -criterion mutation -generateSuite -mem 3000

The paper introducing EvoSuite is here: http://www.st.cs.uni-saarland.de/publications/files/li-ssbse-2011.pdf