集成测试期间的OSGi代码覆盖率

时间:2014-03-12 07:25:07

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

我使用OSGiSOAPUI个捆绑包上运行集成测试。到目前为止,我已经将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>

1 个答案:

答案 0 :(得分:0)

<强>答案:

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

您可以将其配置为TCP服务器,这样您就可以从Eclipse中检查覆盖率报告(它还有一个Eclipse插件也可以连接)。

<强>附加

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

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