问题
I am trying to generate code coverage for my GWT maven project.
It works with my jUnit test
mvn test jacoco:report
But when I run
mvn gwt:test jacoco:report
an empty report is generated.
How does I get code coverage when I'm running the gwt:tests?
Pom.xml
GWT:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<module>${gwtModule}</module>
<gwtVersion>2.5.1</gwtVersion>
<runTarget>https://localhost:8443/dashboard/mainview.jsp</runTarget>
<noServer>true</noServer>
<sourcesOnPath>true</sourcesOnPath>
<hostedWebapp>${war.target}</hostedWebapp>
<mode>HtmlUnit</mode>
</configuration>
<executions>
<execution>
<configuration>
<extraJvmArgs>-Xmx512m</extraJvmArgs>
</configuration>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
Jacoco:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.2.201302030002</version>
<configuration>
<destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</destfile>
<datafile>${basedir}/target/coverage-reports/jacoco-unit.exec</datafile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
回答1:
Enter this command into the command line '
mvn help:describe -Dplugin=org.jboss.errai:jacoco-gwt-maven-plugin -Ddetail=true
and you will get a detailed output from the jacoco-gwt-maven-plugin. In this list you can see all of the configuration parameters that can be set. The error you're getting where it says Error while creating report: basedir c:\Users...... does not exist is related to the snapshotDirectory setting that you see when you run the command I've specifed above. When your project compiles, it creates a folder where all your runtime classes are placed. You need to find where your maven pom is putting these class file and then specify this path in your pom. So say the path location for your class files is 'target/test-classes' then your pom will be:
<plugin>
<groupId>org.jboss.errai</groupId>
<artifactId>jacoco-gwt-maven-plugin</artifactId>
<version>0.5.4.201202141554</version>
<configuration>
<snapshotDirectory>${project.build.directory}/test-classes</snapshotDirectory>
</configuration>
</plugin>
Also one other thing to note kesse is that your initial question is to do with the jacoco-maven-plugin from org.jacoco. I've also failed to get coverage results with this plugin working with GWT Test Cases. However, Thomas Broyer above, points you towards the jacoco-gwt-maven-plugin from the org.jboss.errai group. This Errai group is part of the JBoss developer community and this plugin relates to the Errai Framework. So, in order to get code coverage results from the Errai plugin using the GWT Test Cases, you must use the Errai Framework. To find out more about the Errai Framework go to http://errai.github.io/.
来源:https://stackoverflow.com/questions/15638478/how-do-i-setup-coverage-with-gwt-maven-jacoco