Skip to content

koral--/gradle-pitest-plugin

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 210 commits ahead, 45 commits behind szpak:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Experimental Gradle plugin for PIT Mutation Testing in Android projects

This is a fork of gradle-pitest-plugin which supports Android gradle projects.

Applying plugin in build.gradle

With Gradle plugin portal

plugins {
  id 'pl.droidsonroids.pitest' version '0.2.12'
}
plugins {
  id("pl.droidsonroids.pitest") version "0.2.12"
}

With Maven central repository

buildscript {
  repositories {
    mavenCentral()
    google()
  }
  dependencies {
    classpath("pl.droidsonroids.gradle:gradle-pitest-plugin:0.2.12")
  }
}

plugins {
  id("com.android.application")
  //or id("com.android.library")
  //or id("com.android.test")
  id("pl.droidsonroids.pitest")
}

Usage

pitest<variant> tasks will be created for each build variant (eg. pitestProDebug for pro product flavor and debug build type). Additionally pitest task will run tasks for all variants.

After the measurements a report created by PIT will be placed in ${PROJECT_DIR}/build/reports/pitest/<variant> directory.

For more information see README of source project

Robolectric and UnMock

This plugin by default adds mockable Android JAR (generated by Android Gradle Plugin) to classpath used under pitest tests.

If you are using alternative Android framework in tests, like Robolectric or UnMock Gradle Plugin, you may want to add excludeMockableAndroidJar to pitest configuration eg:

pitest {
    targetClasses = ['com.myapp.*']
    excludeMockableAndroidJar = true
}

In such case default mockable Android JAR won't be added and alternative one will be used under tests.

Troubleshooting

Tests fail when run under pitest but pass without it

Issue occurs when using Android API without mocking it. Pitest verbose logs may list exceptions like ExceptionInitializerError.

The fastest solution is to set android.testOptions.unitTests.returnDefaultValues = true. See Local unit testing documentation to see other consequences of this change.

Packages

No packages published

Languages

  • Groovy 93.7%
  • Java 4.8%
  • Kotlin 1.5%