My project structure is as follows:
myapp
+- module1
| +- src/main
| \- src/unit-tests
+- module2
| +- src/main
| \- src/unit-tests
+- module-FT
| +- src/tests
| \- pom.xml
\- pom.xml
In Jenkins job, the root pom is pom.xml
(because I want the whole project to be built for JaCoCo reports on functional coverage),
and when running the Maven goal for coverage report generation I have specify the pom as module-FT/pom.xml.
Now when the test results are shown, it shows me a total being = FTs + all unit tests in other modules while I want to exclude the UTs from report generation.
But I dont think it has anything to do with JaCoCo, since I am talking about not the JaCoCo report but the Test Results. The unit tests are also getting counted which I dont want. I think this is so because in the Maven root pom below, I have given pom.xml which is causing the whole project to be built. But that's necessary for the JaCoCo to put out the coverage. I am not using JaCoCo plugin since the jenkins version is old and its beyond my scope to upgrade that.
Below are the Jenkins job details:
Build:
- maven version:
maven 3.3.3
- root pom:
pom.xml
- Goals and options:
-B -U -X clean test -f functional-tests/pom.xml -DsuiteXmlFile=src/test/resources/suites/${TEST_SUITE} -Dhostname=${TEST_HOST} -Dprotocol=https -Dport=${TEST_PORT}
Post Steps:
Execute shell
#!/bin/bash # Cleanup workspace rm -rf target echo -------------------------------------- echo TEST_HOST is ${TEST_HOST} echo manifestVersion is ${manifestVersion} echo -------------------------------------- temp=${manifestVersion} appname=(${temp//-/ }) manifestid=(${temp// / }) echo appname is ${appname[0]} echo manifestid is ${manifestid[0]} mkdir -p ${WORKSPACE}/target/classes ### Copy class files to common folder for analysis cp -R ${WORKSPACE}/module-common/target/classes/* ${WORKSPACE}/target/classes cp -R ${WORKSPACE}/module-data/target/classes/* ${WORKSPACE}/target/classes cp -R ${WORKSPACE}/module-event/target/classes/* ${WORKSPACE}/target/classes cp -R ${WORKSPACE}/module-dependencies/target/classes/* ${WORKSPACE}/target/classes cp -R ${WORKSPACE}/module-core/target/classes/* ${WORKSPACE}/target/classes cp -R ${WORKSPACE}/module-api/target/classes/* ${WORKSPACE}/target/classes cp -R ${WORKSPACE}/module-legacy-api/target/classes/* ${WORKSPACE}/target/classes cp -R ${WORKSPACE}/module-messaging/target/classes/* ${WORKSPACE}/target/classes cp -R ${WORKSPACE}/module-service/target/classes/* ${WORKSPACE}/target/classes # build jacoco pom file in order to dump coverage file from app server echo ''' <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.myorg</groupId> <artifactId>CodeCoverage</artifactId> <version>0.0.1</version> <build> <plugins> <!-- Dependencies --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <!-- Copy the ant tasks jar. Needed for ts.jacoco.report-ant . --> <execution> <id>jacoco-dependency-ant</id> <goals> <goal>copy</goal> </goals> <phase>process-test-resources</phase> <inherited>false</inherited> <configuration> <artifactItems> <artifactItem> <groupId>org.jacoco</groupId> <artifactId>org.jacoco.ant</artifactId> <version>0.7.4.201502262128</version> </artifactItem> </artifactItems> <stripVersion>true</stripVersion> <outputDirectory>${basedir}/target/jacoco-jars</outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.4.201502262128</version> <executions> <execution> <id>default-cli</id> <phase>post-integration-test</phase> <goals> <goal>dump</goal> </goals> <configuration> <reset>${Reset}</reset> <address>${TEST_HOST}</address> </configuration> </execution> </executions> </plugin> <!-- Ant plugin. --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>report</id> <phase>post-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <properties> <srcdir>${env.srcDir}</srcdir> <classdir>${env.clsDir}</classdir> <appname>${env.appName}</appname> </properties> <target> <property environment="env" /> <!-- Execute an ant task within maven --> <echo message="Generating JaCoCo Reports" /> <taskdef name="report" classname="org.jacoco.ant.ReportTask"> <classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar" /> </taskdef> <mkdir dir="${basedir}/target/coverage-report" /> <report> <executiondata> <fileset dir="${basedir}/target"> <include name="jacoco.exec" /> </fileset> </executiondata> <structure name="Raptor Coverage Project"> <group name="${env.appName}"> <classfiles> <fileset dir="${env.clsDir}" /> </classfiles> <sourcefiles encoding="UTF-8"> <fileset dir="${env.srcDir}" /> </sourcefiles> </group> </structure> <html destdir="${basedir}/target/coverage-report/html" /> <xml destfile="${basedir}/target/coverage-report/coverage-report.xml" /> <csv destfile="${basedir}/target/coverage-report/coverage-report.csv" /> </report> </target> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.jacoco</groupId> <artifactId>org.jacoco.ant</artifactId> <version>0.7.4.201502262128</version> </dependency> </dependencies> </plugin> </plugins> </build> </project>''' > jacoco_pom.xml
Invoke top level maven targets:
Maven version: 3.3.3
Goals:
-f jacoco_pom.xml jacoco:dump antrun:run@report