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

Code coverage for maven #9539

Open
Shehab-Muhammad opened this issue Jul 24, 2017 · 3 comments
Open

Code coverage for maven #9539

Shehab-Muhammad opened this issue Jul 24, 2017 · 3 comments

Comments

@Shehab-Muhammad
Copy link

Shehab-Muhammad commented Jul 24, 2017

I'm using maven, and I want to find a way to get total coverage for my unit tests as I have GwtMockitoTestRunner and GWTTestCase
I tied to use Emma with maven but it gives me an error

java.lang.IllegalStateException: CONSTANT_info: invalid tag value [8]
at com.vladium.jcd.cls.constant.CONSTANT_info.new_CONSTANT_info(CONSTANT_info.java:103)
at com.vladium.jcd.parser.ClassDefParser$classParser.constant_pool(ClassDefParser.java:168)
at com.vladium.jcd.parser.ClassDefParser$classParser.class_table(ClassDefParser.java:109)
at com.vladium.jcd.parser.ClassDefParser.parseClass(ClassDefParser.java:56)
at com.vladium.emma.instr.InstrProcessorST.handleFile(InstrProcessorST.java:468)

then I tried Jacoco but it gives me 0% coverage
and this's my configuration at pom.xml file

<plugin>
                <groupId>org.jboss.errai</groupId>
                <artifactId>jacoco-gwt-maven-plugin</artifactId>
                <version>0.5.4.201202141554</version>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <propertyName>jacocoArgs</propertyName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>site</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <additionalClasspathElements>
                        <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
                        <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
                    </additionalClasspathElements>
                    <useManifestOnlyJar>false</useManifestOnlyJar>
                    <reuseForks>true</reuseForks>
                    <argLine>${jacocoArgs} -XX:MaxPermSize=512m -Xmx4g -noverify</argLine>
                </configuration>
            </plugin>

please add a way to get code coverage for maven users.

@tbroyer
Copy link
Member

tbroyer commented Jul 24, 2017

JaCoCo, like Emma, is likely to only record coverage when tests are run in dev mode, and tests are run in prod mode by default in GWT 2.8 (as dev mode is deprecated)

AFAIK, there's a way to generate instrumented JS code, but it's not well-integrated into any toolchain (except probably Google's internal build system).
You enable it by setting the gwt.coverage system property to a file whose content is the list of Java source files to instrument, one per line, or a comma-separated list of those files, and the coverage "report" is a JSON object stored in the browser's local storage under the gwt_coverage key.

/cc @rluble as you're among the last ones to have touched coverage implementation, and @cromwellian as you reviewed the initial implementation.

@jomarko
Copy link

jomarko commented Aug 9, 2018

In our project we measure coverage of tests running with GwtMockitoTestRunner. See the configuration below:

<plugin>
<groupId>org.jacoco<groupId>
<artifactId>jacoco-maven-plugin</artifactId>
          <version>${version.jacoco.plugin}</version>
          <executions>
            <execution>
              <id>default-instrument</id>
              <goals>
                <goal>instrument</goal>
              </goals>
            </execution>
            <execution>
              <id>default-restore-instrumented-classes</id>
              <goals>
                <goal>restore-instrumented-classes</goal>
              </goals>
            </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>
                 <!-- conf here -->
              </configuration>
            </execution>
          </executions>
        </plugin>

@eugen-eugen
Copy link

Thank You, jomarko very much,
it seems to be essential to have instrument (offline-instrumentalisation) to get jacoco work properly with GWT.

Also found in google/gwtmockito#65

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

No branches or pull requests

4 participants