我的项目结构如下:
myapp
+- module1
| +- src/main
| \- src/unit-tests
+- module2
| +- src/main
| \- src/unit-tests
+- module-FT
| +- src/tests
| \- pom.xml
\- pom.xml
在 Jenkins 作业中,根pom为pom.xml
(因为我希望为 JaCoCo 功能覆盖率报告构建整个项目),
当我为运行覆盖率报告生成 Maven 目标时,我已将pom指定为 module-FT / pom.xml 。
现在,当显示测试结果时,它显示了总数= FTs +其他模块中的所有单元测试,而我想从报告生成中排除UT。
但我不认为它与 JaCoCo 有任何关系,因为我所说的不是 JaCoCo 报告而是测试结果。 单位测试也被计算在内,我不想要。我认为这是因为在下面的 Maven 根pom中,我已经给出了 pom.xml 导致整个项目的建立。但这对于 JaCoCo 来说是必要的。我没有使用 JaCoCo 插件,因为jenkins版本很旧,而且我的范围超出了我的范围。
以下是 Jenkins 职位详情:
构建
maven 3.3.3
pom.xml
-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}
后续步骤:
执行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
调用顶级maven目标:
Maven 版本: 3.3.3
目标:-f jacoco_pom.xml jacoco:dump antrun:run@report
答案 0 :(得分:0)
建议您首先按照标准maven配置构建项目。这不是一项要求,但可以为您节省一些手动配置。
modulexx
src
main/java
test/java <-- Unit tests always expected here. Usually with suffix '***Test.java'
it/java <-- Integration tests always expected here. Usually with suffix '***IT.java'
然后,您可以配置Maven Surefire插件和maven故障安全插件,分别运行单元测试和集成测试,并生成独立报告。您可以在以下链接中找到有关如何配置pom.xml以使用这些单独文件夹的详细信息。