I want to generate and view a coverage report for a Java-Maven project.
I've added the following to pom.xml:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<formats>
<format>html</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
When I run mvn cobertura:cobertura it builds successfully and reports to the console that Cobertura Report generation was successful but I can't find the report.
If I cd into target/cobertura I find a file called cobertura.ser but I have no idea what to do with it.
Edit: After re-examining the docs, thanks to Andreas_D, I've added the <reporting> tag, but get the same result.
This in the Build section:
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
</plugin>
...
</plugins>
...
</build>
And then this in the Reporting section:
<reporting>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<check></check>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
...
</plugins>
...
</reporting>
Execute mvn cobertura:cobertura
Then look for index.html inside the target/site/cobertura/ folder.
Have a look at the plugin's documentation, there's an example. Pretty sure that you have to add a <reporting> element to actually produce the report.
I just tried here in my project, you can do the following also:
a) run mvn cobertura:cobertura
b) it should generate a folder called 'site'
c) you can open the index.html (inside site/sobertura folder) in whatever browser and inspect the results of coverage.
If nothing works - Try this
http://technikes.com/how-to-generate-code-coverage-report-in-java-jacoco-graphical-report/ you can get code coverage report in html and xml format
This is amazing as I publish my report in html and xml
Related
Requirements
I am refactoring a Java application and am trying to move code out of a war file and into a jar file so it can be used across many different web applications. However, one of the requirements is that the developers still need to use breakpoints within the library. To do so I believe I need to package the source with the compiled code. Below is the build lifecycle
Build Lifecycle
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven
defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Question
When I run mvn package and mvn source:jar package it creates two jar files, respectively
db-0.0.1-SNAPSHOT.jar
db-0.0.1-SNAPSHOT-sources.jar
Then I can attach the source to the dependency.
My question is two-fold
Is there anyway to package the source code into the same jar file as the compiled classes, and
Would this auto-attach the source code to the dependency in Eclipse, so that the developers don't need to do it automatically?
Putting the source code into the JAR is the wrong approach.
You create two JARs (as shown in your question). These JARs go to the repository. Then everyone who uses the JARS will automatically get the -sources as well. In the usual IDEs, like Eclipse and IntelliJ the -sources JAR is automatically used for debugging.
Instead of two Maven runs, you should add the source plugin to your POM. Then the -sources JAR is created during the normal build.
maven-surefire-report-plugin cannot generate HTML reports ,when commands like
mvn clean package site
mvn site
mvn clean deploy site
aren't able to generate successfull build and it does generate HTML reports on successfull build.
When mvn site command is used it gives following error
[WARNING] Error injecting: org.apache.maven.report.projectinfo.CiManagementRepor t
java.lang.NoClassDefFoundError: org/apache/maven/doxia/siterenderer/DocumentCont ent
The only time HTML reports are generated whether the build is failed or not is when i run
mvn surefire-report:report
This is my master POM.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
</build>
</plugins>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<showSuccess>true</showSuccess>
<outputName>Reports</outputName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</reporting>
even the site folder is not generated
If you want your maven build to succeed no matter the result of the unit tests than doing like #khmarbaise suggested it is correct:
mvn clean package -Dmaven.test.failure.ignore=true
If you want your tests to fail the build but still generate a report afterwards the following did the trick for me:
mvn clean test failsafe:integration-test
mvn -Dmaven.test.skip=true surefire-report:report
(Source: https://stackoverflow.com/a/4113187/9478795)
While executing mvn javadoc:javadoc i get this error:
An error has occurred in JavaDocs report generation: Option <stylesheet/> supports only "maven" or "java" value. -> [Help 1]"
But i read here http://maven.apache.org/plugins/maven-javadoc-plugin/examples/stylesheet-configuration.html that <stylesheetfile/> could be a resource in your project directory, i.e. src/main/java, src/main/resources or src/main/javadoc
so why i can not have in my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<stylesheet>src/main/resources/example.css</stylesheet>
</configuration>
</plugin>
?
If you like to configure a file which should be used you have to use the following configuration:
<project>
...
<reporting> (or <build>)
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<stylesheetfile>${basedir}/path/to/your/stylesheetfile.css</stylesheetfile>
...
</configuration>
</plugin>
</plugins>
...
</reporting> (or </build>)
...
</project>
I had a typo not <stylesheet> but <stylesheetfile> should be used.
I have a large project with sub-projects and want to use excludesFile to exclude test failures, and ignore them until the tests are fixed.
I believe there might be a way of achieving this with surefire plugin excludesFile option here.
I am very new to maven and would like get some examples or pointers on how this can be achieved.
To use excludesFile option,
Create a file containing file name patterns of your test files that you want to exclude.Example:Create a file at src/main/resources/exclude.txt with below 2 lines.
**/*1.java
**/*2.java
Add following in your maven-surefile-plugin configuration.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<excludesFile>src/test/resources/exclude.txt</excludesFile>
</configuration>
</plugin>
</plugins>
You are done. All test files ending with 1.java and 2.java will be excluded.
There is other way also to exclude any tests from execution by using configuration in maven-surefire-plugin.
Example:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
More information can be found here.
I have integrated SOAPUI with Maven so that my test cases can be executed with Maven build.
It works fine.
But this integration does not create any formatted report which i can refer to know the test results, like an HTML output.
For the same I added a plugin in my POM.XML (shown below)
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</reporting>
This creates the report, but it does it for all the junit test cases which are in my project.
I can not see any report on the SOAPUI test case.
How can I make the Surefire report contain the SoapUI test results?
Just got it working in my setup.
The solution is "maven-surefire-report-plugin" converts the "TEST*.xml" in to HTML format which is placed in "/targets/surefire-report".So make sure "soapui-maven-plugin" is placing the output in of the "soapui-maven-plugin" in "/targets/surefire-report" directory.
Please see the sample below
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.1.2</version>
<executions>
<execution>
<phase>test</phase>
<goals><goal>test</goal></goals>
<configuration>
<projectFile>${baseDirectory}/src/test/integration/resources/Mobile-Ads-soapui-project.xml</projectFile>
<iface>mobileAdsService</iface>
<outputFolder>${baseDirectory}/target/surefire-reports/</outputFolder>
<junitReport>true</junitReport>
<exportwAll>true</exportwAll>
<printReport>true</printReport>
<testFailIgnore>false</testFailIgnore>
</configuration>
</execution>
</executions>
</plugin>