
Unitcon is a targeted unit test generator for Java.
- Java 8
$ ./setup.sh
You can run Unitcon on the Main
program inside the test
directory by executing the following command.
Suppose the target location is line 11 in Main.java.
./unitcon build test/Main
./unitcon analyze test/Main --target Main.java:11
./unitcon synthesize test/Main --target Main.java:11
If you want to run Unitcon on your project, follow the instructions below.
Create a directory named unitcon-properties
under your project directory target-dir
and write configuration files.
The structure of the target directory will be as follows:
target-dir
|--...
└--unitcon-properties
|--build-command (for building and analyzing the target program)
|--expected-bug (optional)
└--expected-bug-type (optional)
There are three configuration files:
-
build-command (required): This file should contain a sequence of commands to build the target program. See the example. Unitcon creates a single jar file by executing the build sequence of
build-command
. Therefore, Unitcon expects that all dependencies exist in the target directory. If the target program uses a build system such as Maven, thebuild-command
must contain the command such asmvn dependency:copy-dependencies
. -
expected-stack-trace (optional): If you want to detect an exception with a specific stack trace, provide the details such as
at Main.toString(Main.java:11)
. If the file is not provided, Unitcon considers only the final function call. -
expected-bug-type (optional): If you want to detect a specific type of exception at the target location, specify the full name of the exception such as
java.lang.NullPointerException
. If this file is not provided, Unitcon consider all exceptions at the target location.
Build the target project for Unitcon with the following command. The command makes a single jar file that contains all classes of the target project.
$ ./unitcon build PATH/TO/TARGET/DIR
# Analyze the target program.
$ ./unitcon analyze PATH/TO/TARGET/DIR --target [file name]:[line number]
Note that file name
should contains the full path from the target directory to a file.
$ ./unitcon synthesize PATH/TO/TARGET/DIR --target [target location]
If the unit tests have been created successfully, they will be inside the unitcon-out/unitcon-tests
directory.