Maven not outputting junit CHECKSTYLE report - maven

After default config, maven is only outputting the Checkstyle report for source classes, not Junit test classes. Note I'm not looking for the surefire test report output.
from pom.xml:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<configLocation>src/main/resources/apcheckstyle.xml</configLocation>
<module name="LineLength">
<property name="max" value="120"/>
</module>
</configuration>
</plugin>
</plugins>
I changed dependency scope for junit from test to compile:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
Maven is configured to generate the checkstyle reports using the mvn site plugin.
I tried adding a user property includeTestResources as true, but this did not help. The documentation states that the default value is true, so I took it out.
Here is the maven output during checkstyle generation.
from javadocs:
Generating C:\Users\Administrator\Projects\lht657aws\target\site\testapidocs\help-doc.html...
checkstyle plugin runs:
[INFO] Generating "Checkstyle" report --- maven-checkstyle-plugin:2.17
[INFO] There are 210 errors reported by Checkstyle 6.11.2 with src/main/resources/apcheckstyle.xml ruleset.
is following the problem-? all the java under src is getting processed, just java under test is being skipped:
[WARNING] Unable to locate Source XRef to link to - DISABLED
after checkstyle, maven project info report starts
[INFO] Generating "Dependencies" report --- maven-project-info-reports-plugin:2.9

Add the Maven Surefire Report plugin to your pom XML
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<outputDirectory>path/to/the/report</outputDirectory>
</configuration>
</plugin>
And add the goal surefire-report:report to your maven call
See the documentation here: Maven Surefire Report Plugin
EDIT
I've misunderstood the question, try to add this section with desired configurations to your pom.
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<reportSets>
<reportSet>
<id>main_checks</id>
<reports>
<report>checkstyle</report>
</reports>
<configuration>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<includeTestSourceDirectory>false</includeTestSourceDirectory>
<configLocation>config/maven_checks.xml</configLocation>
<outputDirectory>${project.reporting.outputDirectory}/main-checks/</outputDirectory>
</configuration>
</reportSet>
<reportSet>
<id>test_checks</id>
<reports>
<report>checkstyle</report>
</reports>
<configuration>
<sourceDirectory></sourceDirectory>
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<configLocation>config/sun_checks.xml</configLocation>
<outputDirectory>${project.reporting.outputDirectory}/test-checks/</outputDirectory>
</configuration>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>

Maven sure fire plugin is used for generating the Test reports. See the additional documentation here:
http://maven.apache.org/surefire/maven-surefire-report-plugin/
You need to include this plugin in your POM.xml and provide path to create reports (generally a directory in project). While making the build make sure you are including goal for this.

Related

Running Selenium(TestNG) tests from Azure Devops

I'm working on running my automation test scripts (which is a Maven project
based on java and using test ng ) in AzureDevops CI/CD pipeline. I have pushed all my code to Github and created a Maven task to run the tests.
But when I try to run the Maven task , it is not considering testng.xml, where I have all the tests configurations like which tests to be run(order of the tests) and other configuration stuff like listener to create some custom reports. It is just running all the test classes present in my complete Maven project.
Please help me which config / task I should in add in my build inorder for the test to run based on my testng.xml
Below is the Pom.xml
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
TestAutomation
Test
0.0.1-SNAPSHOT
jar
Test
http://maven.apache.org
org.seleniumhq.selenium
selenium-java
3.14.0
org.testng
testng
6.11
compile
org.apache.poi
poi
3.16-beta2
com.relevantcodes
extentreports
2.41.2
commons-io
commons-io
2.6
log4j
log4j
1.2.17
com.googlecode.json-simple
json-simple
1.1.1
<!-- for gson https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>listener</name>
<value>com.qa.ExtentReportListner.ExtentRerportListener</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>

Jenkins SonarQube plugin Multi Module Code Coverage Not Displaying

so we have a Spring Boot maven based project, which we split into multi modules which all works perfectly fine in unit tests and Jenkins, but coverage is not showing up in Sonar at all.
This is the structure of our application:
ApplicationRoot
-SharedCommonModule
--main
---java
-----com...(SomeModule.java)
--test
----com....(SomeModuleTest.java)
-ApplicationModule
--main
---java
-----com...(Application.java)
--test
----com....(ApplicationTest.java)
Parent pom file config:
<properties>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
<jacoco.destFile>${sonar.jacoco.reportPath}</jacoco.destFile>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
SharedCommonModule pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Main ApplicationModule pom file:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.org.Application</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Jenkins SonarQube plugin configuration:
sonar.projectKey=com.Application
sonar.projectName=ApplicationModule
sonar.projectVersion=1.0.0.${BUILD_NUMBER}
sonar.sources=src/main
sonar.tests=src/test
sonar.java.binaries=target/classes
sonar.jacoco.reportPaths=target/jacoco.exec
sonar.modules=ApplicationModule,SharedCommonModule
ApplicationModule.sonar.projectName=ApplicationModule
SharedCommonModule.sonar.projectName=SharedCommonModule
We have researched and tried to hack it together from multiple examples, but nothing seems to work - closest we've got, is for Sonar to show some coverage, while some classes would show 0% coverage even though we know for sure we have UTs that used those classes (tested via IntelliJ).
So, without without the added properties and build xml sections above, we get partial coverage, only for ApplicaitonModule, I think all reported uncovered classes, belong to SharedCommonModule
EDIT: I want to clarify, the combined jacoco.exec file does show coverage for classes when loaded in IntelliJ Coverage tool, but Sonar does not show coverage for the very same classes in its report (which is generated only when I remove the build and properties xml elements in the parent pom).
Please help :)
You have Maven projects, so you should start using Sonar Scanner for Maven.
It is smart enough to generate all parameters for you.
If you remove:
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<jacoco.destFile>${sonar.jacoco.reportPath}</jacoco.destFile>
<destFile>${sonar.jacoco.reportPath}</destFile>
Jenkins SonarQube plugin configuration
add to parent pom file:
<name>ApplicationModule</name>
<properties>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>
<sonar.projectKey>com.Application</sonar.projectKey>
</properties>
add to SharedCommonModule pom file:
<name>SharedCommonModule</name>
add to ApplicationModule.pom file:
<name>ApplicationModule</name>
and finally execute:
mvn sonar:sonar -Dsonar.projectVersion="1.0.0.${BUILD_NUMBER}"
After that you should see missing coverage data.
Btw. it is not recomended to set sonar.projectKey for Maven projects. I set it to the same value, so your project will be accessible under the same link.

How to configure SpotBugs maven plugin to create a full report but check for high threshold only?

I have a legacy maven project and want to integrate the FindBugs successor SpotBugs to create a report of all issues but fail if there a High priority issues only (for now).
It is easy to create the report only without fail ing or to fail on a specific threshold. But when specifying a threshold all issues below that one are also removed from the report.
I have tried to configure the plugin according to to documentation but without success:
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.3</version>
<configuration>
<effort>Max</effort>
<threshold>High</threshold>
<xmlOutput>true</xmlOutput>
<spotbugsXmlOutputDirectory>${project.build.directory}/spotbugs-reports</spotbugsXmlOutputDirectory>
<xmlOutputDirectory>${project.build.directory}/spotbugs-reports</xmlOutputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
I am using Maven 3 and SpotBugs 3.1.3.
Not sure if that helps, it's mostly a workaround.
I have a similar case and what I did was that I placed the configuration in a "reporting" tag (not reportSets). In the "build" tag, I just put the plugin information and the dependencies. The configuration used the default values for the output xml and output folder. I also added file which was filtering out some of the bugs:
<build>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.10</version>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>3.1.11</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.10</version>
<configuration>
<excludeFilterFile>spotbugs_filter.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</reporting>
I then did a
mvn clean install site spotbugs:check
This gave me:
a spotbugsXml.xml file in the build_directory containing ALL of the bugs found (no filters applied).
a report spotbugs.html was produced in target/site which contained the filtered list of bugs.
So, to link this with your issue, I guess that using these "steps" you can have two reports, one with the threshold and another one without.
Does this make sense?

Checkstyle report doesn't show images

I added Checkstyle to my Maven project and it's generating the report, but with broken image/style links. target/site/images/ only contains rss.png. How can I make it generate the report properly with images?
Here is the relevant part from my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
I am running maven with jxr:jxr checkstyle:checkstyle via IntelliJ. I also tried different configuration files (checkstyle.xml) from different sources.
You have to generate the site with mvn site instead of checkstyle:checkstyle to have the styles generated. See also here: https://issues.apache.org/jira/browse/MCHECKSTYLE-127

ChangeLog Plugin Maven - configuration in POM

I want to configure the changelog plugin in my pom.xml...
but there is a reportSets section, so I wonder where I have to put the plugin?
Maybe into the configuration part of the scm plugin (reportPlugins, ...)
The plugin goes in the reporting section of your pom.xml.
The example in their documentation shows how to configure the reportSets:
https://maven.apache.org/plugins/maven-changelog-plugin/examples/selecting-reports.html
Unlike build plugins which are configured under <build>, reporting plugins are nested inside a <reporting> element directly under your root <project> element like so:
<project>
<reporting>
<plugins>
<!-- one or more reporting plugins go here -->
</plugins>
<reporting>
</project>
a bit more particularised:
`
org.apache.maven.plugins
maven-site-plugin
3.3
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changelog-plugin</artifactId>
<version>2.2</version>
<reportSets>
<reportSet>
<id> file-report </id>
<configuration>
<type> range </type>
<range> 30</range>
</configuration>
<reports>
<report>file-activity</report>
</reports>
</reportSet>
</reportSets>
</plugin>
And then... it should work!

Resources