- 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'
}
Expect that the body of checkArg
is fully covered like it is reported by IDEA
checkArg
has missed coverage of checkArgument
while all 2 branches are covered