【问题标题】:Cobertura on Jenkins Duplicate Test RunsJenkins 上的 Cobertura 重复测试运行
【发布时间】:2016-02-11 15:13:13
【问题描述】:

我有一个包含 cobertura 作为我的 Jenkins 运行的一部分的构建。但是,我现在意识到它正在运行我所有的测试两次。

我将项目设置为 Jenkins 中的 Maven 项目。我的目标是:clean coberture:cobertura install

我原以为命令的install 部分会简单地运行安装目标的其余部分,例如 package.json 。但是,它会重新运行编译和所有测试。尽管那里已经进行了测试。

我尝试配置预构建和构建后步骤的不同组合,但我一直遇到问题。在某些组合中,构建工件(例如 jars)永远不会在 Jenkins 上发布。在其他情况下,缺少测试结果。

我想也许我需要将构建重新制作为只是一个 shell 构建。我想我可以运行命令:mvn clean cobertura:cobertura && mvn install -Dmaven.test.skip=true

我认为这会做我想要的。它至少会停止运行所有测试两次。

这是最好的方法还是有其他方法?

这就是我在 POM 中包含 Cobertura 的方式:

  <?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>

  <parent>
    <groupId>com.foo.bar</groupId>
    <artifactId>my-parent</artifactId>
    <version>1.2.1</version>
  </parent>

  <groupId>com.foo.bar.baz</groupId>
  <artifactId>osom</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <description>TODO</description>


  <modules>
    <module>module1</module>
    <module>module2</module>
    <module>module3</module>
  </modules>

  <dependencies>
  </dependencies>

  <build>

    <!-- To define the plugin version in your parent POM -->
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>findbugs-maven-plugin</artifactId>
          <version>3.0.3</version>
        </plugin>
      </plugins>
    </pluginManagement>


    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18</version>
        <configuration>
          <useUnlimitedThreads>true</useUnlimitedThreads>
          <parallel>suites</parallel>
          <reuseForks>false</reuseForks>
          <includes>
            <include>**/*Test.java</include>
            <include>**/Test*.java</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <!-- use mvn cobertura:cobertura to generate cobertura reports -->
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.7</version>
        <configuration>
          <aggregate>true</aggregate>
          <format>xml</format>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
</project>

【问题讨论】:

    标签: java maven jenkins cobertura maven-cobertura-plugin


    【解决方案1】:

    我能想到的最佳方法是在 Jenkins 中使用“Freestyle”项目。

    我让项目运行两个单独的 maven 命令。 mvn clean cobertura:cobertura 和 mvn install -Dmaven.test.skip=true

    这可以防止测试运行两次。

    【讨论】:

      【解决方案2】:

      如果您不想运行两次测试,请使用 qualinsight-mojo-cobertura maven 插件而不是 cobertura-maven-plugin。

      【讨论】:

      • 谢谢,我以后会检查的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-10
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 2019-07-05
      • 2011-01-12
      • 1970-01-01
      相关资源
      最近更新 更多