java web怎么用emma进行代码覆盖率测试
发布网友
发布时间:2022-05-12 06:36
我来回答
共1个回答
热心网友
时间:2024-02-18 22:04
使用 emma 2.1 (emma-stable-2.1.5320-lib) 1. 新建 /home/q/java/emmalib 目录, 将emma.jar 与 emma_ant.jar 放入 2. 复制 /server/bin/mobileserver/runServer.sh 到 runServer_emma.sh 修改启动语句。
使用 emma 2.1 (emma-stable-2.1.5320-lib)
1. 新建 /home/q/java/emmalib 目录, 将emma.jar 与 emma_ant.jar 放入
2. 复制 /server/bin/mobileserver/runServer.sh 到 runServer_emma.sh
修改启动语句
nohup java -Xmx1800M -Xms800m -Xbootclasspath/p:/home/q/java/emmalib/emma.jar -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.EPollSelectorProvider -XX:+AggressiveOpts -XX:+UseParallelGC -server -classpath "$jarFile" com.qunar.common.mobileArc.MobileServer conf/TaLog.property conf/TripServer.property >> $LOG_HOME/error.log 2>&1 &
复制 /server/bin/mobileserver/stopServer.sh 到 stopServer_emma.sh
添加覆盖率导出命令
插入 emma 统计代码
使用root账号
1. 备份mobileserver.jar
cp /server/TripAssistant/mobile-server.jar $MOB_JAR_BAK/mobile-server.jar.{$timestamp}
2. 执行插入命令
java -cp /home/q/java/emmalib/emma.jar emma instr -m overwrite -cp mobile-server.jar -out coverage.em
输出如下:
EMMA: processing instrumentation path ...
EMMA: instrumentation path processed in 3117 ms
EMMA: [1000 class(es) instrumented, 126 resource(s) copied]
EMMA: metadata merged into [/server/TripAssistant/coverage.em]
3. 运行mobileserver runServer_emma.sh
sudo sh /server/bin/mobileserver/stopServer.sh && sudo sh /server/bin/mobileserver/runServer_emma.sh
在 /server/mobileserverlog/error.log中可见:
EMMA: collecting runtime coverage data ...
EMMA: runtime controller started on port [47653]
emma control 进程已启动
[root@l-wap4.beta.cn1.qunar.com /server/mobileserverlog]# netstat -na | grep 47653
tcp 0 0 0.0.0.0:47653 0.0.0.0:* LISTEN 20926/java
4. 执行 覆盖率文件导出命令
java -cp /home/q/java/emmalib/emma.jar emma ctl -connect localhost:47653 -command coverage.get,coverage.ec
可见输出:
EMMA: processing control command sequence ...
EMMA: executing [coverage.get (coverage.ec,true,true)] ...
EMMA: coverage.get: local copy of coverage data merged into [/server/TripAssistant/coverage.ec]
EMMA: coverage.get: command completed in 79 ms
EMMA: control command sequence complete
并且当前目录生成文件 coverage.ec
5. 生成报告
java -cp /home/q/java/emmalib/emma.jar emma report -r html -in coverage.em,coverage.ec
指定源代码生产覆盖率报告(需先上传源码)
java -cp /home/q/java/emmalib/emma.jar emma report -r html -in /server/TripAssistant/coverage.em,/server/TripAssistant/coverage.ec -Dreport.html.out.file=mycoverage/coverage.html -sp /home/liang.zhou/mob_code_dir/mobs_trunk/src/main/java
emma 方式启动 mobserver
==================================
1. 判断mobserver.jar size, 大于5M 为已插入过, 小于5M为未插入(需要执行插入)
2. 执行插入
3. 启动
4. 检查启动状态
47653 端口打开
mobileserver 进程打开
emma 方式停止 mobserver
==================================
1. 检查47653端口打开状态, 检查coverage.em是否存在
2. 导出覆盖率文件 coverage.ec, 备份coverage.em (加上时间戳)
3. 导出覆盖率HTML report (加上对应时间戳)
4. kill mobserver 进程
ls -lt mobile-server.jar
判断 $? == 0
判断mobile-server.jar size是否大于 5M
#!/bin/bash
function stop_mob_server(){
#!/bin/bash
function stop_mob_server(){
pid=`ps aux | grep MobileServer | grep -v grep | awk '
Unknown macro: {print $2}
'`
` kill -9 $
Unknown macro: {pid}
`
sleep 1
echo "Stop mobileserver success."
}
#判断 emma ctl 是否启动
port_check_result=`netstat -na | grep 47653 | awk '
Unknown macro: {print $1}
'`
if [ -z $
Unknown macro: {port_check_result}
]; then
echo "Emma ctl port 47653 is not LISTEN. Coverage.ec export operation aborted."
else
#emma ctl 为启动状态,导出 coverage.ec, 并备份至 /home/q/mobsrv_cov
if []
fi