µJava Home Page |
µJava
(muJava)
is a mutation system for Java programs.
It automatically generates mutants for both traditional mutation testing
and class-level mutation testing.
µJava
can test individual classes and packages of multiple classes.
Tests are supplied by the users as
sequences of method calls to the classes under test
encapsulated in
methods in separate classes
JUnit classes.
µJava is the result of a research collaboration between Yu Seung Ma, PhD candidate at KAIST in Korea, Dr. Jeff Offutt, and Dr. Yong Rae Kwon. Most of the design was by Jeff and YuSeung, and the original software development was done by YuSeung. µJava was modified extensively in 2012 and 2013 by Nan Li. Source files are available on github.
We offer µJava on an "as-is" basis as a service to the community. We welcome comments and feedback, but do not guarantee support in the form of question answering, fault fixing, or improvements (in other words, we don't have money for support, just good intentions). This page contains the following:
March 2007: Laurie Williams and Ben Smith of NC State have modified µJava to be an Eclipse plugin. Their version is available from sourcefourge.
I. Overview
µJava was built by Ma, Offutt and Kwon [1]. µJava uses two types of mutation operators, class level and method level. The class level mutation operators were designed for Java classes by Ma, Kwon and Offutt [2], and were in turn designed from a categorization of object-oriented faults by Offutt, Alexander et al. [3]. µJava creates object-oriented mutants for Java classes according to 24 operators that are specialized to object-oriented faults. Method level (traditional) mutants are based on the selective operator set by Offutt et al. [4]. After creating mutants, µJava allows the tester to enter and run tests, and evaluates the mutation coverage of the tests.
In µJava, tests for the class under test are encoded in separate classes that make calls to methods in the class under test. Mutants are created and executed automatically. Equivalent mutants must be identified by hand.
We have separate descriptions for the class-level mutation operators and the method-level mutation operators used by µJava in PDF.
History
II. Downloading µJava
Although installing µJava is not technically difficult or complicated, it will require a little more effort than installing many commercial packages. µJava can run on Unix, Linux, and Windows platforms. You will need to download and deploy three files; two Java "jar" files and a configuration file.
mujava.jar | µJava system library |
openjava.jar | OpenJava library that is adapted for µJava (OpenJava WWW page) |
mujava.config | A file to specifies the µJava system home directory |
The two jar files should be placed in a directory on disk that all users who need to use µJava can access, for example, in C:\mujava\.
µJava was updated in April 2013 to work with JUnit and generics.
III. Using µJava to Test Classes
The muJava system requires that the Java CLASSPATH be modified to include the muJava jar, the openjava jar, the JUnit library, and and the Java tools.jar files. Also, the general PATH variable must include the java bin directory; this is usually set automatically when java was installed, but not always. Then one GUI (Java applet) is used to generate mutants, the tester must create tests, and another GUI is used to run mutants.
1. Environment Settings for the muJava System
There are three steps to setting up the environment for muJava, (1) CLASSPATH, (2) setting the config file, and (3) creating subdirectories.
Windows
In a DOS window, use the following command (assuming that classes is under C:\mujava):
set CLASSPATH=%CLASSPATH%;C:\mujava\mujava.jar;C:\mujava\openjava.jar;C:\jdk1.7.0\lib\tools.jar;C:\mujava\classes |
CLASSPATH="$CLASSPATH;C:\mujava\mujava.jar;C:\mujava\openjava.jar;C:\jdk1.7.0\lib\tools.jar;C:\mujava\classes" ; export CLASSPATH |
To change your CLASSPATH permanently in Windows, go to Start-settings-Control Panel. Double-click System, go to the Advanced tab, and choose Environment Variables. Edit the CLASSPATH variable or create a new variable if there is none. Add the full path to mujava.jar and openjava.jar to the CLASSPATH.
Unix
In Unix, set the CLASSPATH environment variable.
Assuming the jar files are stored in the home directory of user
mujava:
CLASSPATH=$CLASSPATH:/home/mujava/mujava.jar:/home/mujava/openjava.jar:/java1.4/jdk1.7.0/lib/tools.jar ; export CLASSPATH
Note that the syntax will vary under different shells,
and it will be more convenient to put the command in your setup file
such as .login, .bash_profile, or .bashrc.
Mac
Open the Terminal, type "echo $JAVA_HOME" and "echo $PATH" and make sure the environment variables JAVA_HOME and PATH are correctly set.
If you do not know how to install JDK 7 on a Mac, please read the article about
how to install JDK 7
and how to set up the JAVA_HOME and PATH environment variables.
IMPORTANT: It is necessary to copy the config file to the directory you run the muJava system in.
There should be four subdirectories, used in the following ways.
MuJava_HOME\src | directory for Java files under test |
MuJava_HOME\classes | directory for compiled classes of Java files from MuJava_HOME\src |
MuJava_HOME\testset | directory for test sets |
MuJava_HOME\result | directory for generated mutants |
Create these subdirectories by hand or by using the muJava class "mujava.makeMuJavaStructure".
java mujava.makeMuJavaStructure |
Potential problems: We have identified several potential problems with installing µJava.
2. Generating Mutants with muJava
Important note: You should run all commands in a directory that contains "mujava.config"
java mujava.gui.GenMutantsMain |
This command should bring up a screen similar to the following:
Select the files you want to mutate by clicking in the boxes on the left. Select the mutation operators you want to use by selecting their boxes. Then push RUN.
Note: The class mutation operators produce far fewer mutants. Also note that a number of status messages go to the command window, but not the GUI.
After mutants are generated, you can view the mutants in the "Class Mutants Viewer" and "Traditional Mutants Viewer" tabs, as shown in the following two figures.
You may be interested in knowing where the mutant versions of the classes are stored. They are underneath MuJava_HOME\result\. The following example shows the directory Stack underneath result, with object-oriented mutants in class_mutants and traditional mutants in a separate directory.
A short shell script will help you run µJava. Below is an example shell script for windows that creates mutants:
3. Making a test set
A testset in muJava must be a JUnit test case. JUnit test suite is not supported. Each test is a method that contains a sequence of calls to methods in the class under test. The test methods and the test class should have public access.
Below is an example of a JUnit test class for the class
vendingMachine.
Its name is
testVendingMachine.
The JUnit .class files should be in
the directory MuJava_HOME\testset\.
4. Running mutants.
Run the mutants from another GUI. Start it with the following command:
java mujava.gui.RunTestMain |
You should see the following GUI. You can select which collection of mutants to run, and which testset to use. The "Class Mutants Viewer" and "Traditional Mutants Viewer" tabs will show the source view of the mutants. You can design tests to kill mutants by finding a live mutant, then analyzing the program to decide what input will kill it. Remember that between 5% to 20% of the mutants are typically equivalent.
And the following will run µJava to kill mutants:
IV. Published papers
For awhile we planned to list all papers published using µJava. This became impractical very quickly and is probably impossible. Google scholar lists hundreds of citations to the various µJava papers (241 to reference [1] below in December 2011, 311 in December 2012). We are glad that this tool has been of so much help!
Last update: June 2013, Jeff Offutt and Nan Li
Assistance from the U.S. National Science Foundation
under grant CCR-98-04111 to George Mason University
was greatly appreciated.