Ben Smith, Andy Meneely and Laurie Williams [Contact Authors] |
| 1.0 | What are Mutants? |
| 2.0 | Example |
| 3.0 | What is Jumble? |
| 4.0 | Installing Jumble |
| 5.0 | Jumble with iTrust |
| 6.0 | Exercise: Interpreting Results |
| 7.0 | Exercise: Running Jumble with a JUnit suite |
| 8.0 | Resources |
|
The goal of mutation testing is to evaluate the coverage of your tests. The general idea is to automatically inject faults into the system, re-run the tests, and expect the tests to fail. A version of fault-injected code is called a mutant. A mutant is considered to be live if the tests still pass (usually implying that something was not fully tested). Examining live mutants can shed light on what kinds of test cases your suite is missing. Mutants are modifications of source code that have been modified by mutation operators. These mutation operators are usually simple: for example, changing a "<" to ">". |
|
Example 2.1: Method and Corresponding Unit Test
//original code under test
public class Example
{
public boolean isLessThanThree(int number)
{
return (number < 3);
}
}
//unit test
public class ExampleTest extends junit.framework.TestCase
{
public void testLessThanThree()
{
assertTrue(isLessThanThree(2));
}
public void testLessThanThreeFail()
{
assertFalse(isLessThanThree(3));
}
}
Example 2.2: Mutated Method
public class Example
{
public boolean isLessThanThree(int number)
{
return (number > 3); //the "<" operator mutated
}
}
Notice that with this mutation, the method Because |
Jumble is a Java application that mutates a Java class at the bytecode level and runs its corresponding unit test to determine the number of killed mutants. If no tests failed, the mutant lives. After all the results have been tabulated, Jumble returns a mutation score which is a percentage of all the generated mutants that have been killed. Additionally, your console output will tell you the details regarding each live mutant and this tutorial will tell you how to interpret those results. Jumble will need to be loaded into your copy of Eclipse and must be pointed to the project (or projects) on which it will perform mutation testing. The following instructions contain download links and a short example for setup and use of the Jumble tool. |
Name: Jumble NOTE: Be sure the install location is the default Eclipse directory! |
|
For the exercise, you will run mutation testing on the iTrust source code. If you do not have it, you must download it and import it into your workspace before you continue.
We will be mutating
NOTE:: Jumble does not preconfigure your project choice. You will probably get a stacktrace error on first execution. To fix this, execute the following steps:
ThisIsTheClassName its corresponding test is ThisIsTheClassNameTest. Sometimes, however, we will have multiple unit tests for a single class, so we will need to define a suite of test cases. Instructions for using a test suite are in section 7.0
You can now interpret your Jumble results
|
You should now have Jumble output that looks like the following (not including your test case data generation):
Mutating edu.ncsu.csc.itrust.action.EditHealthHistoryAction Tests: edu.ncsu.csc.itrust.action.EditHealthHistoryActionTest Mutation points = 13, unit test time limit 31.42s ..M FAIL: edu.ncsu.csc.itrust.action.EditHealthHistoryAction:29: changed return value (areturn) .M FAIL: edu.ncsu.csc.itrust.action.EditHealthHistoryAction:40: changed return value (areturn) M FAIL: edu.ncsu.csc.itrust.action.EditHealthHistoryAction:53: 100 (d) -> 101 (e) ....... Score: 76%Here is a list of items and what they mean:
Sometimes the output provided does not give us enough information about what the mutation actually was. This information can be found Jumble website. The first mutation indicates that the code (found in EditHealthHistoryAction):
public String getPatientName() throws DBException, iTrustException{
return authDAO.getUserName(pid);
}
... was changed to ....
public String getPatientName() throws DBException, iTrustException{
return null;
}
..and that no unit test in EditHealthHistoryActionTest detected this change. For this example, we will provide you the unit test case for detecting this mutation:
public void testPatientNameNull() throws Exception {
assertNotNull(action.getPatientName());
}
Paste this code into EditHealthHistoryTest, save it and run jumble on EditHealthHistory again.
NOTE:: You may have to enter the project name again.
Your Jumble output should be:
Mutating edu.ncsu.csc.itrust.action.EditHealthHistoryAction Tests: edu.ncsu.csc.itrust.action.EditHealthHistoryActionTest Mutation points = 13, unit test time limit 45.23s ....M FAIL: edu.ncsu.csc.itrust.action.EditHealthHistoryAction:40: changed return value (areturn) M FAIL: edu.ncsu.csc.itrust.action.EditHealthHistoryAction:53: 100 (d) -> 101 (e) ....... Score: 84%For the rest of this exercise, you must:
|
The previous exercise showed how to run mutation tests using a single unit test in the same package as the source code. While this is the case for many of iTrust's classes, it is not the case for all of them (DAO's, example, are one of these exceptions). Here, we will run Jumble on AccessDAO.java with a suite of tests. The Jumble Eclipse plugin doesn't support this feature however, it does create a runtime configuration we can modify. First, try to run Jumble on edu.ncsu.csc.itrust.dao.mysql.AccessDAO.java. You should get a message in the console like this:Mutating edu.ncsu.csc.itrust.dao.mysql.AccessDAO Tests: edu.ncsu.csc.itrust.dao.mysql.AccessDAOTest Score: 0% (NO TEST CLASS) Mutation points = 41 This error occurred because edu.ncsu.csc.itrust.dao.mysql.AccessDAOTest doesn't exist. We need to create a suite of tests that test AccessDAO.java and point Jumble to it.To create a test suite, first create a new source folder called "mutation" in your iTrust folder. Right-click on iTrust in the package explorer and select "New > Source Folder..."
Now create an appropriate package in the source folder. Right-click on the "mutations" source folder and select "New > Package". Call it "edu.ncsu.csc.itrust.dao.access". Now navigate to the edu.ncsu.csc.itrust.dao.access package in the "unittests" folder. Right click on the "access" package, and go to "New > Other...". Select New JUnit Test Suite.
Hit Next. You should see the following screen. Change the name of the suite from AllTests to AccessDAOSuite. Hit Finish
The new AccessDAOSuite.java has been placed in the access package. Drag it to your new package in the "mutations" folder.
Lastly, we need to make our test suite an actual TestCase. In your new suite, add an extends TestCase to the class declaration.Now we need to point Jumble to our new test suite. Go to Run > Open Run Dialog.... Find Run Jumble(1), and rename it to Run Jumble on AccessDAO Still in the Run dialog, switch over to the Arguments tab. Under Program Arguments, scroll all the way to the bottom. Add the following argument to Jumble: edu.ncsu.csc.itrust.dao.access.AccessDAOSuite. Your arugments should look something like this:
Hit Run. Among many other things, your console should include the following output: Mutating edu.ncsu.csc.itrust.dao.mysql.AccessDAO Tests: edu.ncsu.csc.itrust.dao.access.AccessDAOSuiteExercise: One of the live mutants from this run is the following, M FAIL: edu.ncsu.csc.itrust.dao.mysql.AccessDAO:111: 20 -> 21What does this live mutant mean? Think of two ways you can get rid of this mutant. |