Skip to content

Quick and dirty examples on how to use and extend EvoSuite

Notifications You must be signed in to change notification settings

sesalab/evosuite-examples

Repository files navigation

EvoSuite Examples

Prerequisites

  • Java 8
  • Maven

Getting EvoSuite

Download Precompiled

Go here https://github.com/EvoSuite/evosuite/releases/tag/v1.1.0 and download the two JAR files:

  • evosuite-1.1.0.jar contains the entire EvoSuite logic for generating tests
  • evosuite-standalone-runtime-1.1.0.jar contains the dependencies needed by the JUnit tests generated by EvoSuite

Place them in any directory you want (e.g., your home directory).

Build from Source

  1. Run git clone https://github.com/EvoSuite/evosuite
  2. Run cd evosuite
  3. Run mvn package -DskipTests to generate
  4. Run cp master/target/evosuite-master-1.1.1-SNAPSHOT.jar ~/evosuite-1.1.1.jar
  5. Run cp standalone_runtime/target/original-evosuite-standalone-runtime-1.1.1-SNAPSHOT.jar ~/evosuite-standalone-runtime-1.1.1.jar

EvoSuite in Action

In this examples EvoSuite 1.1.0 is already downloaded and part of this repository.

Basic Setup

  1. Run git clone https://github.com/sesalab/evosuite-examples
  2. Run cd evosuite-examples
  3. Run java -jar evosuite-1.1.0.jar to check if everything works well (you should see a text output on the terminal).
  4. Run cd Tutorial_Stack
  5. Run mvn compile test-compile to get the .class of the class under test, i.e., tutorial.Stack
  6. Run java -jar ../evosuite-1.1.0.jar -class tutorial.Stack -projectCP target/classes to start the generation with default setting (60 seconds of budget). You can kill the process at anytime by issuing CTRL+C
  7. Run mvn dependency:copy-dependencies to copy JUnit and Hamcrest JARs into target/dependency (you can avoid this step if you can find these JAR in .m2/ directory)
  8. Run javac -cp .:target/classes:../evosuite-standalone-runtime-1.1.0.jar:target/dependency/junit-4.12.jar:target/dependency/hamcrest-core-1.3.jar -d target/test-classes evosuite-tests/tutorial/*.java to compile the tests in evosuite-tests/tutorial and place them in target/test-classes
  9. Run java -cp .:target/classes:target/test-classes:../evosuite-standalone-runtime-1.1.0.jar:target/dependency/junit-4.12.jar:target/dependency/hamcrest-core-1.3.jar org.junit.runner.JUnitCore tutorial.Stack_ESTest to execute all the JUnit test methods generated by EvoSuite.

You should see all tests pass (OK).

Special Setup

Repeat the above steps but change the 6th one with the following:

  • Run java -jar ../evosuite-1.1.0.jar -class tutorial.Stack -projectCP target/classes -criterion branch -Dsearch_budget=20 -Dminimize=false to start the generation with default setting (60 seconds of budget).

Checkout all the possible settings with java -jar ../evosuite-1.1.0.jar -listParameters

Generating Tests for Many Classes

Repeat the above steps but change the 6th one with the following:

  • java -jar ../evosuite-1.1.0.jar -target target/classes to generate tests for all classes found in target/classes and its subdirectories. You can also add the option -prefix packageName to specify which package you want to test.

Check Tests Quality

  1. Seed a bug into Stack class (e.g., switch negate a logical operator)
  2. Run mvn compile to recompile Stack class
  3. Run java -cp .:target/classes:target/test-classes:../evosuite-standalone-runtime-1.1.0.jar:target/dependency/junit-4.12.jar:target/dependency/hamcrest-core-1.3.jar org.junit.runner.JUnitCore tutorial.Stack_ESTest

If you see at least one failure then the tests are not so bad!

Check the Regression Test Suite

  1. Seed a bug into Stack class (e.g., switch negate a logical operator)
  2. Run mvn compile to recompile Stack class
  3. Run java -jar ../evosuite-1.1.0.jar -class tutorial.Stack -projectCP target/classes to regenerate the EvoSuite tests
  4. Run javac -cp .:target/classes:../evosuite-standalone-runtime-1.1.0.jar:target/dependency/junit-4.12.jar:target/dependency/hamcrest-core-1.3.jar -d target/test-classes evosuite-tests/tutorial/*.java to compile the tests in evosuite-tests/tutorial and place them in target/test-classes
  5. Run java -cp .:target/classes:target/test-classes:../evosuite-standalone-runtime-1.1.0.jar:target/dependency/junit-4.12.jar:target/dependency/hamcrest-core-1.3.jar org.junit.runner.JUnitCore tutorial.Stack_ESTest to execute all the JUnit test methods generated by EvoSuite.

You will see that all tests pass, meaning that the assertions are build on the current behaviour of the class!

About

Quick and dirty examples on how to use and extend EvoSuite

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages