zoukankan      html  css  js  c++  java
  • 怎么实现在jenkens页面配置sonar,以及如何利用cobertura插件实现sonar页面显示测试覆盖率

          最近我在工作中遇到需要给项目中每个模块配置Sonarqube,来看看测试用例覆盖的情况。在这个过程中遇到了一些问题,也查了很多资料。现在记录一下具体应该怎么配置。

          先展示一下实现的效果:

          

                           图一

    It will show:

                                                                     图二

    现在来看看具体配置:

    要enable Sonarqube, 需在 job --> configure --> Post-build Actions 配置Branch 和 JDK 信息:

                                                                           图三

    配置好了以后,SonarQube 可以在页面上显示出来了,点击进去,效果图:【与图二相比,缺少了Coverage信息】

                                                                       图四

    如何利用cobertura插件实现sonar页面显示测试覆盖率:

    需要在pom.xml文件中配置一下信息:

    <plugin>
      <groupId>org.codehaus.sonar</groupId>
      <artifactId>sonar-maven3-plugin</artifactId>
      <version>3.5</version>
    </plugin>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>cobertura-maven-plugin</artifactId>
      <version>2.6</version>
      <configuration>
        <formats>
          <format>xml</format>
          <format>html</format>
        </formats>
        <aggregate>true</aggregate>
        <instrumentation>
          <includes>
            <include>**/*.class</include>
          </includes>
        </instrumentation>
      </configuration>
      <executions>
        <execution>
          <id>clean</id>
          <phase>pre-site</phase>
          <goals>
            <goal>clean</goal>
          </goals>
        </execution>
        <execution>
          <id>instrument</id>
          <phase>site</phase>
          <goals>
            <goal>instrument</goal>
            <goal>cobertura</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

    并在job --> configure --> Build 配置  Goals and options:

                                                                                        图五

    保存配置,重新build这个job,就行了。

  • 相关阅读:
    20165103 第四周查漏补缺
    20165103 2017-2018-2 《Java程序设计》第3周学习总结
    20165103 2017-2018-2 《Java程序设计》第2周学习总结
    20165103 2017-2018-2 《Java程序设计》第1周学习总结
    MySQL事务一致性理解
    mysql的事务四个特性以及 事务的四个隔离级别
    序列化和反序列化的简单理解
    内存溢出和内存泄漏的区别,产生原因以及解决方案
    oracle入门学习之oracle数据库结构
    Java微服务(Spring-boot+MyBatis+Maven)入门教程
  • 原文地址:https://www.cnblogs.com/Jenny22/p/6484425.html
Copyright © 2011-2022 走看看