java应用测试报告生成(一): sonarqube配合Jenkins生成测试报告及覆盖率
环境准备:
1.Jenkins集成环境(安装 sonarqube插件)
2.安装sonarqube服务(下载sonarqube安装包并解压,目录到"sonarqube-5.4/bin/linux-x86-64"下运行命令"./sonar.sh start"启动服务)
启动服务后jps看到如下结果
Jps
SearchServer
WrapperSimpleApp
WebServer
Jenkins配置:
项目配置:
项目pom.xml添加如下配置(添加及配置jacoco插件):
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<encoding>UTF-</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1..v20140903</version>
<configuration>
<stopPort></stopPort>
<stopKey>foo</stopKey>
<scanIntervalSeconds></scanIntervalSeconds>
<webApp>
<contextPath>/p_test</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<!--覆盖率 -->
<profiles>
<profile>
<id>coverage-per-test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<!--忽略某个目录的测试代码 -->
<includes>
<include>**/*Test.java</include>
</includes>
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>3.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.7.5.201505241946</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
项目运行无误就可以提交Jenkins了,找到Jenkins的该项目配置,在add post-build steps 中选择"Invoke Standalone SonarQube Analysis"
在Analysis properties中添加如下内容:
# must be unique in a given SonarQube instance
sonar.projectKey=p_test
# this is the name displayed in the SonarQube UI
sonar.projectName=p_test
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-
sonar.svn.username=***
sonar.svn.password.secured=***
sonar.java.coveragePlugin=jacoco
sonar.sources=src/main/java
sonar.tests=src/test/java/
sonar.binaries=target/classes
sonar.junit.reportsPath=target/surefire-reports
sonar.surefire.reportsPath=target/surefire-reports
注意填写访问代码源的账号和密码,其他如果需要可以更改项目名,收集报告的目录等:
编译项目,点击sonarqube按钮可以进入查看页面:
点击测试可以继续看到测试的方法以及通过情况.
java应用测试报告生成(一): sonarqube配合Jenkins生成测试报告及覆盖率的更多相关文章
- centos7搭建sonarqube环境+jenkins部署全流程
一.简介sonarqube是一个用于代码质量管理的开源平台,用于管理源代码的质量 不遵循代码标准sonar可以通过PMD,CheckStyle,Findbugs等等代码规则检测工具规范代码编写.潜在的 ...
- 集成TFS Build生成与SonarQube获取代码分析结果
软件项目在开发过程中,往往由于任务重.时间紧等原因忽略软件代码的质量和规范检查,只注重软件功能的开发和交付.等软件交付上线以后,由于代码质量导致的问题会耗费开发和运维人员的大量时间.研发表明,项目上线 ...
- .net持续集成sonarqube篇之 sonarqube与jenkins集成(插件模式)
系列目录 Jenkins通过插件集成Sonarqube 通过上一节我们了解了如何配置以使jenkins ci环境中可以执行sonarqube构建,其实Sonarqube官方也提供了jenkins插件以 ...
- Jenkins+Allure测试报告+飞书机器人发送通知
一.前言 之前讲了jenkins如何设置定时任务执行脚本,结合实际情况,本篇讲述在jenkins构建成功后,如何生成测试报告,以及推送飞书(因为我公司用的是飞书,所以是发送到飞书机器人). 本次实践搞 ...
- jbe 可以用来修改Java class的字节码,配合jd-gui 使用
jbe 可以用来修改Java class的字节码,配合jd-gui 使用
- AWS DevOps – 配合Jenkins和CodeDeploy实现代码自动化部署
AWS DevOps – 配合Jenkins和CodeDeploy实现代码自动化部署 Amazon ElastiCache 连接至 Redis 节点 通过 AWS Command Line Inter ...
- SonarQube与Jenkins结合提高代码质量
首先,为什么需要SonarQube? 1.WriteClean Code 1)全局健康报告 2)关注新增的问题 3)强制QualityGate 4)Issue详情及建议- 详情参考:https:/ ...
- jmeter接口测试-调用java的jar包-csv参数化请求-BeanShellPreProcessor生成验签作为请求验证参数-中文乱码----实战
背景及思路: 需求:要做 创建新卡 接口的测试,要求: 1. 不需要每次手动修改请求参数. 方案:文中先用excle将数据准备好,导出为csv格式,再用jmeter的csv请求进行参数化 2. 卡号需 ...
- 用Java实现在【520,1314】之间生成随机整数的故事
做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 在未来城市工作的的程序员小木,做了一个梦,梦到自己在塔鲁姆的街道上看到一个姑娘,这个姑娘从远处走向他,脸上带着微笑.让小木 ...
随机推荐
- 第五、六章:图像&链接
图像有很多存储格式:JPEG.png.gif等,它们的文件大小也不同,使用的图片类型对于页面响应速度有不同的要求.下面就会简单阐述不同的格式的图片的特点. 1.JPEG格式 JPEG格式适用于彩色照片 ...
- 图的连通性:有向图强连通分量-Tarjan算法
参考资料:http://blog.csdn.net/lezg_bkbj/article/details/11538359 上面的资料,把强连通讲的很好很清楚,值得学习. 在一个有向图G中,若两顶点间至 ...
- 1、第一个SpringMVC程序
1.创建如下项目结构 2.在src下的com.springmvc下创建User.java package com.springmvc; public class User { private Stri ...
- 串string (KMP)
1.Definition 串string,是零个或多个字符组成的有限序列.一般记作S="a1a2a3...an",其中S是串名,双引号括起来的字符序列是串值:ai(1<= i ...
- [kuangbin带你飞]专题四 最短路练习 POJ 3268 Silver Cow Party
题意: 在一个有向图中求n头牛从自己的起点走到x再从x走回来的最远距离 思路一开始是暴力跑dij…… 讲道理不太可能…… 然后就百度了一下 才知道把矩阵转置的话就只需要求两次x的单源最短路…… /* ...
- python 列表、字典的方法
# 列表最后新增元素 li = [11, 22, 33] print(li) li.append(44) # 对原列表最后增加一个元素 print(li) 执行如下: [11, 22, 33][11, ...
- OC之消息调用过程
Bird * aBird = [[Bird alloc] init]; [aBird fly]; 中对 fly 的调用,编译器通过插入一些代码,将之转换为对方法具体实现 IMP 的调用,这个 IMP ...
- wpf 数据绑定的4种形式
1.source 2.element 3.relativesource 4.datacontent
- bshare
function shareInit(){ $('.bshare').each(function(index, element) { var c1 = $('.p3-dialog').attr('ti ...
- jquery1.8.3和1.11.3的用法区别
学习js啦dom的对象 发现好复杂 不够简洁 所以我就用法强大的jquery来做功课 突然就遇到attr的方法对复选属性的checked取不了值 给我返回undefined 我查好久都没查出问题 结果 ...