m0c0-maven-plugin Maven Plugin

A Maven plugin written in Kotlin that supports mutation testing for Java projects. MoCo uses the bytecode manipulation approach and it applies optimizations with Git Mode and database caching, thus mutation testing execution time can be reduced significantly

License

License

Categories

Categories

Maven Build Tools Ant
GroupId

GroupId

io.github.phantran
ArtifactId

ArtifactId

m0c0-maven-plugin
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

m0c0-maven-plugin Maven Plugin
A Maven plugin written in Kotlin that supports mutation testing for Java projects. MoCo uses the bytecode manipulation approach and it applies optimizations with Git Mode and database caching, thus mutation testing execution time can be reduced significantly
Project URL

Project URL

https://github.com/phantran/moco
Project Organization

Project Organization

TranPhan
Source Code Management

Source Code Management

https://github.com/phantran/moco

Download m0c0-maven-plugin

How to add to project

<plugin>
    <groupId>io.github.phantran</groupId>
    <artifactId>m0c0-maven-plugin</artifactId>
    <version>1.0.1</version>
</plugin>

Dependencies

compile (20)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.31
org.jetbrains.kotlinx : kotlinx-coroutines-core jar 1.4.2
org.jetbrains.kotlin : kotlin-reflect jar 1.4.31
org.junit.platform : junit-platform-launcher jar 1.7.0
org.junit.platform : junit-platform-suite-api jar 1.6.2
org.junit.jupiter : junit-jupiter jar 5.7.0
junit : junit jar 4.12
org.testng : testng jar 6.9.10
org.ow2.asm : asm jar 8.0
org.ow2.asm : asm-commons jar 8.0
org.ow2.asm : asm-util jar 8.0
org.ow2.asm : asm-analysis jar 8.0
com.h2database : h2 jar 1.4.200
com.fasterxml.jackson.module : jackson-module-kotlin jar 2.12.0
org.jsoup : jsoup jar 1.13.1
org.eclipse.jgit : org.eclipse.jgit jar 5.9.0.202009080501-r
org.json : json jar 20180813
io.github.microutils : kotlin-logging jar 1.6.22
org.slf4j : slf4j-simple jar 1.7.29
org.apache.maven : maven-model jar 3.3.9

provided (4)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.3.9
org.apache.maven : maven-core jar 3.3.9
org.apache.maven : maven-artifact jar 3.3.9
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.6.0

test (7)

Group / Artifact Type Version
org.apache.maven : maven-compat jar 3.3.9
org.apache.maven.plugin-testing : maven-plugin-testing-harness jar 3.3.0
io.kotest : kotest-runner-junit5-jvm jar 4.3.0
io.kotest : kotest-assertions-core-jvm jar 4.3.0
io.mockk : mockk jar 1.10.2
org.jetbrains.kotlin : kotlin-test-junit jar 1.4.31
io.kotest : kotest-framework-engine-jvm jar 4.3.0

Project Modules

There are no modules declared in this project.

MoCo

example workflow License Quality Gate Status Maven Central

This is the m0c0-maven-plugin.

A Maven plugin written in Kotlin that supports mutation testing for Java projects.

Mutation testing is computationally expensive, and that prevents mutation testing from being applied in big projects and CI/CD pipelines. MoCo is a mutation testing tool that uses the bytecode manipulation approach, and it applies optimization such as Git Mode (only execute mutation tests for changed source classes) and database caching, thus mutation testing execution time in MoCo can be reduced significantly. With the applied optimization, MoCo has good performance, and it can calculate mutation scores without re-running mutation tests for the whole project under test.

MoCo was originally developed to support Gamekins which is a Jenkins plugin that uses a gamification approach to motivate software testing activities. More information about Gamekins Jenkins plugin can be found here: https://github.com/se2p/gamekins

Project requirements

  • Java 8+
  • Apache Maven 3

Test Frameworks

MoCo supports TestNG and JUnit (3, 4, 5)

Setup Project

Clone this repository and install it by using Maven install command:

mvn install

While developing MoCo, a quick installation without testing and generating descriptor to test MoCo in your local repository can be done with:

mvn install -Ddescriptor.skip -Dtest.skip

Usage

pom.xml

MoCo is available on Maven Central, and it can be used easily by adding the following information to pom.xml file of your project (replace MOCO-VERSION with a MoCo version, e.g. 1.0.1):

  • To dependencies tag
<dependency>
    <groupId>io.github.phantran</groupId>
    <artifactId>m0c0-maven-plugin</artifactId>
    <version>MOCO-VERSION</version>
</dependency>
  • To build tag
<plugin>
    <groupId>io.github.phantran</groupId>
    <artifactId>m0c0-maven-plugin</artifactId>
    <version>MOCO-VERSION</version>
    <executions>
        <execution>
            <goals>
                <goal>moco</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The default Maven phase of MoCo is verify phase, if you want to change the phase that executes MoCo, just change the execution configuration as below

<execution>
    <goals>
        <goal>moco</goal>
    </goals>
    <phase>ENTER-PHASE</phase>
</execution>

Trigger MoCo

If MoCo is added as a dependency of your project as above, it can be triggered with mvn verify (if execution phase is kept as default). It can also be executed alone with this command mvn m0c0:moco

Because MoCo uses compiled test classes and compiled source classes of your project for mutation testing, please make sure MoCo is executed after the compile phase and test phase of Maven so that all compiled sources classes and compiled test classes are available and updated in the build (or target) folder.

Target source classes and test classes for mutation are configurable through codeRoot and testRoot parameters. If codeRoot and testRoot are not specified, MoCo will use the default folder path information given by Maven. You could check the configuration section or use helpmojo goal for more details about all configurable parameters of MoCo.

It's highly recommended to configure your codeRoot and testRoot for MoCo mutation testing if your project is big. It will take a long time to finish if you have a big project with hundred of source classes and test classes.

Example: We wanted to have mutation tests only for source classes inside org/example (assume there is a corresponding org/example folder in built test classes folder), then the configuration is:

<codeRoot>org/example</codeRoot>
<testRoot>org/example</testRoot>

To remedy the problem of re-running mutation tests for unchanged source classes with corresponding test classes, MoCo offers Git Mode. Git Mode is ON by default, it helps reduce execution time significantly by only considering changed classes. We can turn it off with

<gitMode>false</gitMode>

Mutation score is not calculated by default. You can enable it by adding this to your configuration

<enableMetrics>true</enableMetrics>

Mutation testing is computationally expensive even with the bytecode manipulation approach. A big project with hundred of tests can take hours to finish. To speed it up you can use more worker threads. MoCo uses 2 threads by default. Example: Using 3 threads.

<numberOfThreads>3</numberOfThreads>

Below is an example configuration that uses MoCo version 1.0.1, Git Mode ON, mutation score calculation enabled, debug messages logging enabled, test timeout in preprocessing phase (collecting mutations) as 500ms, and use 3 threads for parallel execution:

<plugin>
    <groupId>io.github.phantran</groupId>
    <artifactId>m0c0-maven-plugin</artifactId>
    <version>1.0.1</version>
    <configuration>
        <gitMode>true</gitMode>
        <debugEnabled>true</debugEnabled>
        <enableMetrics>true</enableMetrics>
        <preprocessTestTimeout>500</preprocessTestTimeout>
        <numberOfThreads>3</numberOfThreads>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>moco</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Report

After each execution, MoCo will produce a file named moco.json. The default path to this file is **\moco\mutation\moco.json (inside your project output build folder). This moco.json file contains information about all mutations that MoCo has collected and executed so far.

Configuration

Details about more configurable parameters of MoCo will be updated here later. At the moment, you could use the helpmojo command to learn more about it.

mvn m0c0:help -Ddetail=true

Contributing

If you find a problem with MoCo and wanted to fix it, it would be very helpful to create a ticket along with your pull request. The ticket in issues should describe clearly what your pull request is about. Please create new branch from the development branch, implement the changes, then create a pull request to development branch after finishing.

License

This software is licensed under the terms in the file named "LICENSE" in the root directory of this project. This project has dependencies that are under different licenses.

Author Information

Tran Phan

[email protected]

This project was developed as a part of my work at the Chair of Software Engineering II, University of Passau.

Versions

Version
1.0.1
1.0