Open jsoltes opened 7 years ago
I experience the same thing when I use the @RunWith(GwtMockitoTestRunner.class), JaCoCo will not consider that test execution and report as 0% coverage. The GwtMockitoTestRunner uses javassist.Loader class for bytecode manipulation and as far as I know JaCoCo does not work if the class under test has been modified during runtime. My feeling is that GwtMockitoTestRunner has never worked with JaCoCo (regardless what the change log says).
I'm not particularly familiar with JaCoCo - @rsauciuc, can you comment if it is/was working for you?
The only change in GwtMockito to support JaCoCo is to ensure that we use the standard classloader for everything under the org.jacoco
package. Classes under test will go through the GwtMockito classloader to do things like stub native methods and unfinalize some methods, so if that process interferes with JaCoCo there might not be a fix. But we should leave the bytecode of normal methods untouched.
At the time I made the fix it was working for us, we were using JaCoCo in offline mode, doing bytecode instrumentation at build time.
In a different project, we had a similar problem with the agent competing with other instrumentation to make changes to the class files, and we switched the flag (classdumpdir, I think) to write out the class files after they were transformed, so JaCoCo's report task could match the binary coverage data with the actual classes.
I have set jacoco to do the offline instrumentation and it is working even for classes annotated @RunWith(GwtMockitoTestRunner.class). So far this is the only way to make it work I know about.
Thanks @jsoltes , with offline instrumentation it works as excepted and shows the coverage. Maybe it will help for others, this is how I enabled it with maven:
<properties>
<jacocoVersion>0.7.9</jacocoVersion>
<jacoco.skip.instrument>true</jacoco.skip.instrument>
</properties>
<dependencies>
...
<dependency>
<!-- must be on the classpath -->
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>${jacocoVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacocoVersion}</version>
<executions>
<execution>
<id>jacoco-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
<configuration>
<skip>${jacoco.skip.instrument}</skip>
</configuration>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
<configuration>
<skip>${jacoco.skip.instrument}</skip>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
To execute without coverage
mvn clean install
With coverage (and instrument):
mvn clean install -Djacoco.skip.instrument=false
Any idea how to do this for ant? Thanks
Should this still work with GWT 2.8.2 and GwtMockito + plain old JUnit Tests? Somehow do not get it to work at all. Does not even create the jacoco.exec file ("Skipping JaCoCo execution due to missing execution data file."). Anybody managed to find a solution?
Jacoco code coverage tool should be supported since the version 1.1.5 (implemented by @rsauciuc ). However when we run jacoco on the sample project in this project, we are getting zero coverage. We are using following configuration in the parent pom: