Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JaCoCo support not working #65

Open
jsoltes opened this issue Feb 3, 2017 · 7 comments
Open

JaCoCo support not working #65

jsoltes opened this issue Feb 3, 2017 · 7 comments

Comments

@jsoltes
Copy link

jsoltes commented Feb 3, 2017

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:

<plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>${version.jacoco.plugin}</version>
          <executions>
            <execution>
              <id>default-prepare-agent</id>
              <goals>
                <goal>prepare-agent</goal>
              </goals>
              <configuration>
                <propertyName>surefire.argLine</propertyName>
              </configuration>
            </execution>
            <execution>
              <id>default-report</id>
              <phase>prepare-package</phase>
              <goals>
                <goal>report</goal>
              </goals>
            </execution>
            <execution>
              <id>default-check</id>
              <goals>
                <goal>check</goal>
              </goals>
              <configuration>
                <haltOnFailure>${jacoco.haltOnFailure}</haltOnFailure>
                <rules>
                  <rule>
                    <element>BUNDLE</element>
                    <limits>
                      <limit>
                        <counter>LINE</counter>
                        <value>COVEREDRATIO</value>
                        <minimum>${jacoco.line.coveredratio.minimum}</minimum>
                      </limit>
                    </limits>
                  </rule>
                </rules>
              </configuration>
            </execution>
          </executions>
</plugin>
@nukesz
Copy link

nukesz commented Apr 6, 2017

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).

@ekuefler
Copy link
Collaborator

ekuefler commented Apr 9, 2017

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.

@rsauciuc
Copy link
Contributor

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.

@jsoltes
Copy link
Author

jsoltes commented Apr 11, 2017

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.

@nukesz
Copy link

nukesz commented Apr 13, 2017

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

@JonCook
Copy link

JonCook commented Jun 22, 2017

Any idea how to do this for ant? Thanks

@zeitwesen
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants