Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladimirdolzhenko/58b880b573e9f831398bd58ea232e12d to your computer and use it in GitHub Desktop.
Save vladimirdolzhenko/58b880b573e9f831398bd58ea232e12d to your computer and use it in GitHub Desktop.

jacoco issue #568

Steps to reproduce

  • JaCoCo version: 0.7.8, 0.7.9
  • Operating system: Windows, Linux
  • Tool integration: Gradle

let's say we have following class

package com;

import static com.google.common.base.Preconditions.checkArgument;

public class FastPreconditions {

    public static void checkArg(
            boolean expression,
            String errorMessageTemplate,
            int arg1
    ) {
        // fast check, avoid vargs + autoboxing
        if (!expression) {
            checkArgument(expression, errorMessageTemplate, arg1);
        }
    }
}

and test case for it

package com;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static com.FastPreconditions.checkArg;

public class FastPreconditionsTest {
    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void simple1IntArg() throws Exception {
        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage("msg 1");
        checkArg(false, "msg %s", 1);
    }

    @Test
    public void simple1IntArgPasses() throws Exception {
        checkArg(true, "msg %s", 1);
    }
}

and build.gradle

apply plugin: 'java'
apply plugin: 'jacoco'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "${buildDir}/jacocoHtml"
    }
}

dependencies {
    compile 'com.google.guava:guava:19.0'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Expected behaviour

Expect that the body of checkArg is fully covered like it is reported by IDEA

Actual behaviour

checkArg has missed coverage of checkArgument while all 2 branches are covered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment