0

I'm trying to include mutation testing for my Android local UnitTests. I found https://pitest.org/ framework which I tried to include using the "officially" recommended gradle plugin from here: https://gradle-pitest-plugin.solidsoft.info/

Gradle Wrapper version: 6.5.1

But I can't figure out how to get it up and running. The docs on the plugins webpage are very fragmented and so I don't know if my gradle configuration is even correct.

My build.gradle file:


buildscript {
    ext.kotlin_version = '1.3.72'

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.5.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My build.gradle (app) file:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'info.solidsoft.pitest'

android { ... }

dependencies { ... }

pitest {
    targetClasses = ['training.your.app.data.viewmodel.*']  
    pitestVersion = '1.5.1'
    threads = 4
    outputFormats = ['XML', 'HTML']
    timestampedReports = false
}

With this approach the IDE (AndroidStudio 4) gradle sync tells me:

Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method pitest() for arguments [build_w05scwyltsg8pepn5z5mp7e1$_run_closure3@651693d3] on project ':app' of type org.gradle.api.Project.

If I try to do it via gradlew pitest I get the same result.

My best guess is I'm lacking a lot of gradle knowledge. Any advise?

Patrick Pötz
  • 369
  • 5
  • 15
  • 1
    There are issues using the standard java gradle plugin for android projects, but this fork should be compatible -> https://github.com/koral--/gradle-pitest-plugin – henry Jul 27 '20 at 08:17
  • Thanks for this hint. But I'm afraid this doesn't work either. When including with Plugin Portal I get `Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'reporting' for root project 'your.training' of type org.gradle.api.Project.` on sync. When including via maven central I get: `Could not find pl.droidsonroids.gradle:gradle-pitest-plugin:0.2.4.` – Patrick Pötz Jul 27 '20 at 09:41
  • Seems that `0.2.4` and `0.2.3` are somehow not in the maven central repository (`Could not resolve all artifacts`). But I was able to get a successful gradle sync with `0.2.2`. Nevertheless `0.2.2` runs into an issue (`The value for task ':app:pitestDebug' property 'mainClass' is final and cannot be changed any further.`) which was fixed in `0.2.4`. Quite a dilemma. – Patrick Pötz Jul 27 '20 at 10:11
  • Opened an issue for this problem here: https://github.com/koral--/gradle-pitest-plugin/issues/66 The simple truth: Artifacts for `0.2.4` haven't been uploaded to any repository. – Patrick Pötz Jul 27 '20 at 10:26

1 Answers1

0

Thanks to henry's comment I was able to get pitest running with a fork of the gradle-pitest-plugin (https://github.com/koral--/gradle-pitest-plugin).

Long story short:

build.gradle

buildscript {
    ext.kotlin_version = '1.3.72'

    repositories {
        mavenCentral()
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'pl.droidsonroids.gradle:gradle-pitest-plugin:0.2.2'
    }
}

build.gradle (app)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'pl.droidsonroids.pitest'

android { ... }

dependencies { ... }

pitest {
    reportDir = 'build/pitest/reports'
    targetClasses = ['training.your.app.data.viewmodel.*']
    threads = 6
    outputFormats = ['HTML']
    timeoutConstInMillis = 20000
    verbose = true
}

This won't work with Gradle version 6.5.1. The author of this plugin claims to have this issue fixed with the plugin version 0.2.4. But this version hasn't been published to maven central yet.

So use Gradle 6.3 with pl.droidsonroids.gradle:gradle-pitest-plugin:0.2.2 and you're good to go.

Patrick Pötz
  • 369
  • 5
  • 15