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.提升自己 我有一个乐园,面向编程,春暖花开! 在未来城市工作的的程序员小木,做了一个梦,梦到自己在塔鲁姆的街道上看到一个姑娘,这个姑娘从远处走向他,脸上带着微笑.让小木 ...
随机推荐
- 基于Bootstrap的炫酷jQuery slider插件
简要教程 这是一款在原生bootstrap slider的基础上制作效果非常炫酷的jQuery slider插件.该slider插件可以自定义slider的颜色.形状.透明度和tooltip等属性,美 ...
- 3DTouch--2
苹果太贱了! 3D Touch 只能在真机上面试,模拟器没办法玩! ------------- 描述有点粗燥.....有6S 在手上玩得童鞋会更加清楚,只有玩过才更加体验到. 首先 有几个要知道的手势 ...
- Python学习笔记_Chapter 4数据保存到文件
1. What For 将基于内存的数据存储到磁盘上,达到持续存储. 2. HOW 方法一: 将数据写到文件中 常规的处理方式 #file.x被打开的文件,model打开文件的方式 out=open( ...
- Linux C/C++编译环境搭建
1. 配置GCC,LInux 在安装后已经有GCC了,但可能文件不全,我们可以利用 sudo apt-get install build-essential 安装 2. 安装文本编辑器 sudo ap ...
- OMCS ——卓尔不群的网络语音视频框架
作为.NET平台上的开发人员,要开发出一个像样视频聊天系统或视频会议系统,非常艰难,这不仅仅是因为.NET对多媒体的支持比较有限,还因为网络语音视频这块涉及到了很多专业方面的技术,而.NET在这些方面 ...
- 2016 ACM/ICPC Asia Regional Dalian ICPC大连现场赛
讲道理我挺想去大连的…… 毕竟风景不错…… 而且这次能去北京也是靠大连网络赛这一场拉开的优势…… 一道补图最短路一道数学推论简直爽爆…… 当然 除了这一场 其他场都非常划水…… 上次看到别人的博客用这 ...
- MySQL binlog 查看信息
1)按时间筛选 mysqlbinlog --start-datetime="2009-09-14 0:20:00" --stop-datetim="2009-09-15 ...
- 杭电21题 Palindrome
Problem Description A palindrome is a symmetrical string, that is, a string read identically from le ...
- iOS 计算两个坐标之间的距离
//第一个坐标 CLLocation *before=[[CLLocation alloc] initWithLatitude:29.553968 longitude:106.538872]; //第 ...
- buffer小解
Buffer代表一个缓冲区,存储二进制数据,是字节流 创建: 创建Buffer有4种方式: 1.new Buffer(size) 以字节为单位创建指定大小的Buffer eg: var buf= ne ...