Link Search Menu Expand Document

Kotlin Support

Requires pitest 1.9.0 or above.

Maven Central

Background

Although Kotlin compiles to normal java bytecode, some language features require compiler generated constructs that do not map back to the source code. This results in confusing mutants that are hard to interpret, and junk mutations which cannot be reproduced by mistakes in the source code.

The kotlin plugin filters out these junk mutations and removes confusing noise from mutant descriptions.

Support is currently provided for the following language features

  • Coroutines
  • Destructuring
  • Intrinsics
  • Safe casts
  • Autogenerated accessors
  • Lateinit
  • Unmatched when clauses in enums and sealed classes
  • Var accessors
  • Inlined code
  • Non-null types

The plugin also filters equivalent mutants where pitest has introduced ‘empty’ returns into methods that already return empty collections using Kotlin library methods, and supports ‘empty’ return values for Kotlin specific types including

  • IntRange
  • LongRange
  • CharRange
  • Sequence
  • CoroutineContext

The Kotlin plugin is currently in beta. Although it greatly enhances developer experience when mutating Kotlin, we are still gathering feedback to improve it further.

We’re looking for teams to try the plugin against their codebases and report back the issues they find. If you’d like to help bring mutation testing to the Kotlin eco-system, please get in touch.

Inlined Functions

Inlined functions are a challenge for bytecode based mutation testing. When an inlined function is used, its bytecode is copied into the client class. This creates two problems

  • The client class contains instructions that do not map to its source code
  • The inlined function itself is never executed (instead copies of it are executed in various locations)

Since release 0.1.2 the Kotlin plugin addresses the first issue by filtering out mutations where it detects that the bytecode has been inlined. The second problem remains an issue if your codebase contains inline function definitions. These areas of code will appear to be uncovered by any test. Any mutants seeded into them will survive.

Installation

Before you can use the integration, you must first acquire a licence. Access to the kotlin plugin is automatically included with our Pro licence. If you don’t have a pro licence, and would like access to the beta e-mail us for a free licence.

The licence file must be named cdg-pitest-licence.txt and placed at the root of the project.

The plugin must be placed on the classpath of the pitest tool (not on the classpath of the project being mutated).

E.g for maven

<plugin>
  <groupId>org.pitest</groupId>
  <artifactId>pitest-maven</artifactId>
  <version>1.9.4</version>
    <dependencies>
      <dependency>
        <groupId>com.groupcdg</groupId>
        <artifactId>pitest-kotlin-plugin</artifactId>
        <version>0.1.3</version>
      </dependency>
    </dependencies>
</plugin>

Or for gradle

dependencies {
  pitest 'com.groupcdg:pitest-git-plugin:version number'
}

See gradle-pitest-plugin documentation for more details.