集成测试和单元测试覆盖率合并

父文章

   人人都是测试专家- testCase怎么写,才能完备._个人渣记录仅为自己搜索用的博客-CSDN博客_测试case怎么写

首先要明白一点,maven里单元测试和集成测试的java是混合在一起的,没有默认的目录。需要你自己去配置哪些时单元测试,哪些是集成测试。

默认不跑,只有安装了surfire插件才跑单测,只有安装了failureSafe才跑test目录下IT结尾的类。默认能识别junit等.

详见

maven集成测试 http://blog.csdn.net/fei33423/article/details/51090574

*使用 Cobertura

 1 集成测试可直接调用代码

      1.1 https://blog.jayway.com/2008/12/13/getting-coverage-for-integration-tests/

      其方法是利用maven工具,增加一个profile mvn -P  利用<build-helper-maven-plugin>插件的将集成测试代码代码移动到src/test/java中。 见附件:

      这样就能一起跑。 不能动态的将两份文档根据协议格式合并。

     1.2  通过这里的说明,如果是在同一个module下跑的集成测试和单元测试,可以

             http://www.mojohaus.org/cobertura-maven-plugin/usage.html

    1.3 http://aroundthecode.org/2014/07/07/unit-and-integration-tests-coverage-with-sonarqube-and-jacoco/

http://blog.javabien.net/2012/11/23/combine-surefire-tests-and-failsafe-tests-coverage/

http://stackoverflow.com/questions/13031219/how-to-configure-multi-module-maven-sonar-jacoco-to-give-merged-coverage-rep

     1.4 sonar可以合并jacco的单元测试和集成测试的覆盖率,cobertura 不行

http://stackoverflow.com/questions/23977082/can-sonar-calculate-overall-test-coverage-when-using-cobertura

http://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Integration+Tests+for+Java+Project

2 集成测试不能直接调用源代码,需要依赖第三方协议和容器,比如http

官网文档 http://www.mojohaus.org/cobertura-maven-plugin/instrumentingDeploymentArtifact.html

  1.1   https://blog.avisi.nl/2012/09/25/calculating-the-code-coverage-of-integration-tests/

   这篇文章主要讲解了如何利用Cobertura 命令行将war包注入统计代码,然后把生成的 cobertura.ser 放入到tomcat启动。 跑Selenium单测,跑完后会得到数据,通过Usecobertura-report to generate the XML or HTML report. 生成结果

  1.1 进阶,上诉这套流程,可以在maven里 通过jetty和Cobertura的插件配置结合起来

    http://stackoverflow.com/questions/8034913/cobertura-and-jetty

附录:

 <profiles>
   <profile>
      <id>itcov</id>
      <build>
         <plugins>
            <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>build-helper-maven-plugin</artifactId>
               <version>1.1</version>
               <executions>
                  <execution>
                     <id>add-test-source</id>
                     <phase>generate-sources</phase>
                     <goals>
                        <goal>add-test-source</goal>
                     </goals>
                     <configuration>
                        <sources>
                          <source>src/it/java</source>
                        </sources>
                     </configuration>
                  </execution>
               </executions>
            </plugin>
         </plugins>
      </build>
   </profile>
</profiles>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值