Carma Documentation

Alexander Rau

Last update: 2008-03-28


Table of Contents

1. Introduction
Mutation Testing
Brief description
Advantages
Difficulties
Carma
2. Using Carma
General process
Ant
Attaching
Processing
Report Generation
Maven 2
Attaching
Processing
Report Generation
Carma Reports
3. Carma Development
Carma Extensions
Test Runners
Mutation Operators
Build Integration Adapters
Carma Core Modifications
4. FAQs

Chapter 1. Introduction

General introduction on Carma and Mutation Testing

Mutation Testing

This section describes what Mutation Testing is and explains the advantages and disadvantages.

Brief description

Mutation Testing is a known method of white-box testing. The basic principle is to perform a single modification of the code under test (called Mutation) in a controlled manner and validate whether existing test cases for the code fail or pass. There are two possible outcomes:

  • At least one test case fails which means the mutation was detected by the test harness or
  • No test cases fail and the mutation was not detected by the test harness

The above conditions can be interpreted as follows. If at least one test fails the mutation was revealed by the test harness. This is considered to be a good thing as it shows that the code location where the mutation was performed is covered to a certain degree by a test case which is sensitive to errors of the original code. That means that an error in this code location is less likely. The more mutations are performed and detected by the test harness the more stable is the code. Given the case that a mutation is performed and the test harness does not react with at least one failing test case the modified code location is obviously not very well-tested as errors can survive without test cases showing that.

The conclusion therefore is: The more mutations survive the worse is the quality of your test harness. Accordingly the more mutations are revealed by the test harness the better is the quality of your test harness.

Combined with the fact that the quality of the test cases has a direct relation to the quality of the code base (e.g. your product) delivers a very solid and objective metric for code quality.

Prototypical Mutation Testing tools can be found in the public and prove the feasability of mutation testing. However no mutation testing software has been publicly available which is easy to use and mature to seriously consider it as a tool for software developers in a productive environment.

Advantages

The compelling advantage of mutation testing is that it is a stable and non-subjective metric in terms of expressiveness and interpretation. Compared to code coverage metrics for example mutation testing results not just tell you wether code has been executed during test exeuction. It tells you whether the test is sensitive to errors in a certain location or not. Consider how easily code coverage tools and their users can be tricked by a developer who creates one big integration test case without any assertions. A code coverage tool would show you that most of the code has been executed which would be interpreted as "well-tested". As the existence of assertions is not considered at all during code coverage evalation the expressiveness is obviously very weak.

In times of outsourcing and large development teams mutation testing is a big benefit for a mature quality verification of code deliveries on a technical level. It reliably identifies lacking or missing test cases and either indicates need for further actions (like for example rework of certain code deliveries) or confirms a high quality of the code base and its test cases.

Difficulties

While Mutation Testing can be done manually in theory it's a process which practiacally must be done in an fully automated manner. The reason is that - based on the principle of mutation testing - it requires large amounts of processing power to execute the test harness. Therefore in small projects (a few hundert lines) can easily be verified by using Mutation Testing. However larger projects require much more processing resources as larger projects have a much larger code base and therefore many more mutations must be created and injected and furthermore the number of test cases most often correlates with the size of the project which means more testcases must be executed as well. Without further action the time required for executing one complete run grows non-linearily.

Carma

Carma is performing Mutation Testing in a fully automated manner. For performance and reliability reasons mutations are exclusively performed on byte code level. This allows faster in-memory processing compared to Mutations on source code level (no recompilation required) and avoids potential pitfalls with source code mutations (e.g. mutating javadoc or comments).

Carma provides XML and HTML reports about the Mutation Testing results. XML reports are useful for processing the results in a machine-readable manner. HTML results are intented for software developers who use Carma to improve their code.

Chapter 2. Using Carma

General process

These steps are required in general to sucessfully run Carma on a product code base:

  1. Attach and configure Carma for an existing build of the code base under test
  2. Perform a Carma mutation run
  3. Run Carma's report generation based on the results of the previous step
  4. Investigation of Carma reports

The configuration of Carma is the step where most of the user interaction is required. However most of the effort is done only one time which means once you have properly setup Carma for a build you can run Carma as often as you like.

The integration of Carma into an existing build is done in a build-specific manner. That means the type of your build tool determines the steps required. Therefore the following sections describe the integration in respect to the steps integration, processing and report generation completely according to the build technology used.

Independently from which build system you are actually using there are several attributes which must be passed to carma from the build system. Here is a definition of all variables and a short explanation of their meaning:

classpath

A fixed list of either relative or absolute classpath entries pointing to the carma artifacts in java classpath syntax. Currently required: AntPlugin.jar, Integration.jar, EventListeners.jar, Core.jar:ReportModel.jar, Utilities.jar, TestRunners.jar, Transformers.jar, Resolvers.jar

classesDir

A fixed list of either relative or absolute classpath entries pointing to the code under test in java classpath syntax.

testClassesDir

A fixed list of either relative or absolute classpath entries pointing to the code of the test classes in java classpath syntax.

sourceDir

A fixed list of either relative or absolute classpath entries pointing to the sources of the code under test

dependencyClassPathUrls

A fixed list of either relative or absolute classpath entries pointing to the required dependency artifacts of the code under test

outputDirectory

The location where the reports should be stored

Ant

Apache Ant is a legacy build scripting language which is widely spread. Carma can be attached to an Ant build by using the Ant Plugin in the Carma distribution.

Attaching

For attaching Carma to an Ant build Carma provides a few targets and task definitions which must be added in a central location of the target builds ant scripts. The following snippet can be used as a template:

<taskdef name="carma" classpath=".." classname="com.retroduction.carma.ant.AntCarmaTest" />
        
<target name="carma">
	<carma classesDir=".." testClassesDir=".." dependencyClassPathUrls=".."/>
</target>

<taskdef name="carmareport" classpath=".." classname="com.retroduction.carma.ant.AntCarmaReport" />

<target name="carmareport">
	<carmareport sourceDir=".." outputDirectory=".." />
</target>

The first task definition and target is required for processing the code with Carma via the build system. The second task definition and target is required for creating HTML reports via the build system. One goal serves the activation of a Carma run, the second goal allows activation of the report generation mechanism of Carma.

The values for the attributes ("..") above must be replaced with proper values depending on your environment

Processing

Carma processes the code base by typing the following statement on the command line:

ant carma

Report Generation

Carma reports can be generated by calling:

ant carmareport

Maven 2

Apache Maven 2 is a newer build system more and more used. Carma can be attached to a Maven 2 build by using the Maven 2 Plugin in the Carma distribution.

Attaching

For attaching Carma to an Maven 2 build Carma provides a goals which must be used in the pom.xml of the target build. The following snippet can be used as a template:

<build>
	<plugins>
		<plugin>
			<groupId>com.retroduction.carma</groupId>
			<artifactId>MavenPlugin</artifactId>
			<configuration>
				<mutationConfigFile>./mutationConfig.xml</mutationConfigFile>
			</configuration>
			<executions>
				<execution>
					<id>mutationtest</id>
					<goals>
						<goal>mtest</goal>
					</goals>
				</execution>
				<execution>
					<id>mutationreport</id>
					<goals>
						<goal>mreport</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

As you can see the required declaration in the pom.xml is pretty simple. the property mutationConfigFile points to a separate configuration file. This file defines the required attributes depending on your build environment and must be adapted accordingly.

Processing

Carma processes the code base by typing the following statement on the command line:

mvn mutationtest

Report Generation

Carma reports can be generated by calling:

mvn mutationreport

Carma Reports

Chapter 3. Carma Development

Note

This chapter has not yet been written.

Carma Extensions

This chapter explains how to extend Carma based on the plugin interfaces for various aspects.

Test Runners

Mutation Operators

Build Integration Adapters

Carma Core Modifications

This chapter explains how to modify Carma's Core Engine.

Chapter 4. FAQs

General Questions

4.1. Which languages and platforms does Carma support?
4.2. Which mutations does Carma support?
4.3. Which test runners does Carma support?

4.1.

Which languages and platforms does Carma support?

Only Java is currently supported.

4.2.

Which mutations does Carma support?

4.3.

Which test runners does Carma support?