Java 如何从功能测试报告中排除单元测试?

Java 如何从功能测试报告中排除单元测试?,java,maven,unit-testing,jenkins,jacoco-maven-plugin,Java,Maven,Unit Testing,Jenkins,Jacoco Maven Plugin,我的项目结构如下: myapp +- module1 | +- src/main | \- src/unit-tests +- module2 | +- src/main | \- src/unit-tests +- module-FT | +- src/tests | \- pom.xml \- pom.xml 在Jenkins job中,根pom是pom.xml(因为我希望整个项目都是为JaCoCo关于功能覆盖率的报告构建的), 在运行Maven goal for covera

我的项目结构如下:

myapp
+- module1
|  +- src/main
|  \- src/unit-tests
+- module2
|  +- src/main
|  \- src/unit-tests
+- module-FT
|  +- src/tests
|  \- pom.xml
\- pom.xml
在Jenkins job中,根pom是
pom.xml
(因为我希望整个项目都是为JaCoCo关于功能覆盖率的报告构建的), 在运行Maven goal for coverage report generation时,我将pom指定为模块FT/pom.xml

现在,当显示测试结果时,它向我显示了一个总数being=FTs+其他模块中的所有单元测试,而我想从报告生成中排除UTs

但我不认为这与杰科科有关,因为我说的不是杰科科报告,而是测试结果单元测试也得到了计数,这是我不想要的。我认为这是因为在下面的Maven根pom中,我给出了pom.xml,这导致了整个项目的构建。但这是必要的JaCoCo发布的报道。我没有使用JaCoCo插件,因为jenkins版本很旧,我无法升级它

以下是詹金斯的工作细节:

建造:

  • maven版本:
    maven 3.3.3
  • 根pom:
    pom.xml
  • 目标和选项:
    -B-U-X清洁测试-f功能测试/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
    
    #/bin/bash
    #清理工作区
    射频靶
    回音--------------------------------------
    回显测试主机为${TEST\u HOST}
    echo manifestVersion为${manifestVersion}
    回音--------------------------------------
    temp=${manifestVersion}
    appname=(${temp/-/})
    manifestid=(${temp//})
    echo appname为${appname[0]}
    echo manifestid为${manifestid[0]}
    mkdir-p${WORKSPACE}/target/classes
    ###将类文件复制到公用文件夹进行分析
    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
    #构建jacoco pom文件,以便从app server转储覆盖率文件
    回音''
    4.0.0
    com.myorg
    编码覆盖
    0.0.1
    org.apache.maven.plugins
    maven依赖插件
    jacoco依赖蚂蚁
    复制
    过程测试资源
    假的
    org.jacoco
    org.jacoco.ant
    0.7.4.201502262128
    真的
    ${basedir}/target/jacoco jars
    org.jacoco
    jacocomaven插件
    0.7.4.201502262128
    默认cli
    整合后测试
    倾倒
    ${Reset}
    ${TEST_HOST}
    org.apache.maven.plugins
    maven antrun插件
    1.7
    报告
    整合后测试
    跑
    ${env.srcDir}
    ${env.clsDir}
    ${env.appName}
    org.jacoco
    org.jacoco.ant
    0.7.4.201502262128
    ''jacoco_pom.xml
    
  • 调用顶级maven目标:

    Maven版本:3.3.3

    目标:
    -f jacoco_pom.xml jacoco:dump antrun:run@report


  • 建议您首先按照标准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'
    
    modulexx
    src
    main/java
    
    test/java您能添加插件配置吗?您在插件公共API中看到了吗?更新的问题。请检查。FTs位于外部文件夹中,无法更改。请检查我所做的编辑,这可能更有意义。您仍然可以利用maven的单独运行程序来执行测试。请参阅有关为集成测试配置源路径的文档。这将为结果提供单独的输出文件夹,然后您可以将CI工具配置为readHi,我在中遵循了regex解决方案。但是,在jenkins的测试运行和jacoco报告制作工作中,我遇到了一个错误:
    [error]找不到目标'run@report在plugin org.apache.maven.plugins:maven-antrun-plugin:1.3中,在可用的目标帮助中,运行->[help 1]
    听起来像是输入错误。将完整的命令行粘贴到注释中。请参见post最后一部分的post步骤。目标就在那里。一样。总而言之