4

My gradle pitest is not able to give me the right results. It looks like it is not able to locate my test files.

I have the following build.gradle file:

apply plugin: "java" apply plugin: "maven" apply plugin: "info.solidsoft.pitest"

group = "myorg" version = 1.0

repositories {
    mavenCentral() }

sourceSets.all { set ->
    def jarTask = task("${set.name}Jar", type: Jar) {
        baseName = baseName + "-$set.name"
        from set.output
    }

    artifacts {
        archives jarTask
    } }

sourceSets {
    api
    impl    main{       java {          srcDir 'src/api/java'           srcDir 'src/impl/java'      }   }   test {      java {          srcDir 'src/test/java'      }   } }

buildscript {
    repositories {
        mavenCentral()
        //Needed only for SNAPSHOT versions
        //maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
    }
    dependencies {
        classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.1.6'
    } }

dependencies {
    apiCompile 'commons-codec:commons-codec:1.5'

    implCompile sourceSets.api.output
    implCompile 'commons-lang:commons-lang:2.6'

    testCompile 'junit:junit:4.9'
    testCompile sourceSets.api.output
    testCompile sourceSets.impl.output
    runtime configurations.apiRuntime
    runtime configurations.implRuntime }

jar {
    from sourceSets.api.output
    from sourceSets.impl.output }

pitest { println sourceSets.main

    targetClasses = ['doubler.*']       targetTests  = ['doubler.*']    verbose="on" }

THe output is stored in the correct folder. And when I run gradle test, it also runs fine.

  • How many tests classes do you have? What do they look like. The output suggests that pitest has found a single test class but it provides no coverage. – henry Jan 22 '16 at 20:10

1 Answers1

2

Some additional information about this issue was supplied in the pitest user group.

https://groups.google.com/forum/#!topic/pitusers/8C7BHh-Vb6Y

The tests being run look like this.

@Test
public void testIt2() {
    assert new DoublerImpl().testIt(1) == 2;
}

Pitest is correctly reporting that these tests provide 0% coverage of the class. There is no coverage because the assert keyword has been used.

Unless the -ea flag is set in the JVM running the tests assertions are disabled. There is basically hidden if block around this code generated by the compiler

@Test
public void testIt2() {
    if (assertionsEnabled) {
      assert new DoublerImpl().testIt(1) == 2;
    }
}

As assertions are not enabled no code is executed.

To fix the issue use the built in JUnit assertions instead.

http://junit.sourceforge.net/javadoc/org/junit/Assert.html

henry
  • 5,923
  • 29
  • 46