【问题标题】:OSGi Code Coverage during Integration Testing集成测试期间的 OSGi 代码覆盖率
【发布时间】:2014-03-12 07:25:06
【问题描述】:

我正在使用 SOAPUI 对 OSGi 捆绑包运行集成测试。到目前为止,我已经将 SOAPUI 与 Maven 集成,后者在 OSGi 捆绑包上运行集成测试*(在 Apache Karaf 中运行)*。我正在尝试找出如何进一步增强我的pom.xml 以在运行时为捆绑包计算 code coverage?

谁能给点建议?

我有以下 pom.xml:

    <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>org.m2m.aricent.parent</groupId>
  <artifactId>CustRestExampleOsgi</artifactId>
  <version>1.0</version>

  <packaging>pom</packaging>
  <name>CustRestExampleOsgii</name>


  <modules>
      <module>M2mCustImplProvider</module>
      <module>M2mCustInterface</module>
      <module>M2mRestCustConsumer</module>
  </modules>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <karaf.deploy.build.folder>
        G:\apache-karaf-3.0.0.RC1\deploy
    </karaf.deploy.build.folder>
  </properties>

  <dependencies>
    <!-- needed to execute Integration tests instrumented with Cobertura -->
    <dependency>
        <groupId>net.sourceforge.cobertura</groupId>
        <artifactId>cobertura</artifactId>
        <version>1.9.4</version>
        <scope>test</scope>
    </dependency>
  </dependencies>

<pluginRepositories>
   <pluginRepository>
      <id>eviwarePluginRepository</id>
      <url>http://www.soapui.org/repository/maven2/</url>
   </pluginRepository>
    <pluginRepository>
     <id>cobertura-it-maven-plugin-maven2-release</id>
     <url>http://cobertura-it-maven-plugin.googlecode.com/svn/maven2/releases</url>
     <snapshots>
         <enabled>false</enabled>
     </snapshots>
     <releases>
         <enabled>true</enabled>
     </releases>
 </pluginRepository>
</pluginRepositories>

  <build>
      <plugins>
         <plugin>
            <groupId>eviware</groupId>
            <artifactId>maven-soapui-plugin</artifactId>
            <version>4.5.1</version>
            <configuration>
                <junitReport>true</junitReport>
                <exportAll>true</exportAll>
                <projectFile>C:\Documents and Settings\gur31659.AD\workspace\CustomerRestfulExampleOSGi\test-classes\cust.xml</projectFile>
                <outputFolder>C:\Documents and Settings\gur31659.AD\workspace\CustomerRestfulExampleOSGi\test_output</outputFolder>
                <testFailIgnore>true</testFailIgnore>
            </configuration>
            <executions>
                <execution>
                    <id>wsn-server-test</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
             <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-it-maven-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <formats>
                    <format>xml</format>
                    <format>html</format>
                </formats>
                <check>
                    <haltOnFailure>false</haltOnFailure>
                </check>
            </configuration>
            <executions>
                <execution>
                    <id>cobertura-clean</id>
                    <phase>clean</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
                <execution>
                    <id>cobertura-instrument</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>instrument</goal>
                    </goals>
                </execution>
                <execution>
                    <id>cobertura-report</id>
                    <phase>pre-site</phase>
                    <goals>
                        <goal>report-only</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.6.5.201403032054</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                    <execution>
                            <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                           <goal>report</goal>
                        </goals>
                   </execution>
                    <!--
                        Prepares the property pointing to the JaCoCo runtime agent which
                        is passed as VM argument when Maven the Failsafe plugin is executed.
                    -->
                    <execution>
                        <id>pre-integration-test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the path to the file which contains the execution data. -->
                            <destFile>${jacoco.it.execution.data.file}</destFile>
                            <!--
                                Sets the name of the property containing the settings
                                for JaCoCo runtime agent.
                            -->
                            <propertyName>failsafeArgLine</propertyName>
                        </configuration>
                    </execution>
                    <execution>
            <id>default-prepare-agent-integration</id>
            <goals>
              <goal>prepare-agent-integration</goal>
            </goals>
          </execution>


                    <!--
                        Ensures that the code coverage report for integration tests after
                        integration tests have been run.
                    -->
                    <execution>
                        <id>post-integration-test</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the path to the file which contains the execution data. -->
                            <dataFile>${jacoco.it.execution.data.file}</dataFile>
                            <!-- Sets the output directory for the code coverage report. -->
                            <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
                        </configuration>
                    </execution>                   
            </executions>
        </plugin>
                <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.2.v20120308</version>
            <configuration>
                <stopPort>18043</stopPort>
                <stopKey>STOP</stopKey>
                <connectors>
                    <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                        <port>18042</port>
                    </connector>
                </connectors>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                    <configuration>
                        <!-- Needed in order to to code coverage on SoapUI tests -->
                        <classesDirectory>${project.build.directory}/generated-classes/cobertura</classesDirectory>
                        <useTestScope>true</useTestScope>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                        <daemon>true</daemon>
                        <contextPath>/myIntegrationTestsContext</contextPath>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <minimumTokens>20</minimumTokens>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>2.3</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
            </plugin>
            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-it-maven-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <formats>
                    <format>html</format>
                    <format>xml</format>
                </formats>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>report-only</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
        </plugins>
    </reporting>

</project>

【问题讨论】:

    标签: maven osgi integration-testing code-coverage soapui


    【解决方案1】:

    答案:

    我建议你试试Jacoco。 Jacoco 可以配置为java agent,因此它可以与任何Java 应用程序一起使用。在这种情况下,您应该在部署包的 Karaf 服务器上配置 Jacoco。

    您可以将其配置为 TCP 服务器,以便您可以从 Eclipse 实时查看覆盖率报告(它也有一个 Eclipse 插件可以连接)。

    额外:

    我们使用 Jacoco 和 maven plugin,它启动一个 OSGi 容器并在构建的集成测试阶段对它们运行测试。如果 felix 或 equinox 足够了,你也可以使用它。

    它支持创建自定义 dist 包,因此如果您将 Karaf 服务器捆绑为 dist 包,也可以使用它。遗憾的是,关于创建自定义服务器类型的文档仍然不多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-11
      • 2018-05-28
      • 2017-06-19
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多