Jacoco代码覆盖率生成使用Ant脚本实现

本文介绍了如何在Ubuntu中编写Ant脚本,将Jenkins部署流程标准化,包括编译、打包、启动JaCoCo服务、运行测试并生成覆盖率报告的过程。
摘要由CSDN通过智能技术生成

语法挺简单的,一看就能了解个大概,就是把Ubuntu中的指令放到一个脚本里,方便后续在Jenkins上部署,自动生成各种报告

1、gedit build.xml

2、

<project name="JaCoCoCoverage" default="generateReport" basedir=".">

    <!-- Target to start Java service with JaCoCo agent -->
    <target name="javac">
        <exec executable="javac">
            <arg line="/home/wd/ApplicationTest/Junit/com/wd/test/JUTest.java"/>
        </exec>
    </target>

    <target name="cp" depends="javac">
        <exec executable="cp">
            <arg line="-rf /home/wd/ApplicationTest/Junit/com/wd/test/JUTest.class /home/wd/ApplicationTest/JunitClass/com/wd/test"/>
        </exec>
    </target>
    <target name="jar" depends="cp">
        <exec executable="jar">
            <arg line="cfm /home/wd/ApplicationTest/JUTest.jar /home/wd/ApplicationTest/Manifest.txt *.class"/>
        </exec>
    </target>

    <target name="startJavaService" depends="jar">
        <exec executable="java">
            <arg line="-javaagent:/home/wd/ApplicationTest/jacocoagent.jar=includes=com.wd.test.*,output=tcpserver,port=6300,address=172.22.10.61 -cp /home/wd/ApplicationTest/junit-4.10.jar:/home/wd/ApplicationTest/JunitClass:/home/wd/ApplicationTest/JUTest.jar org.junit.runner.JUnitCore com.wd.test.JUTest"/>
        </exec>
    </target>

    <!-- Target to run tests and generate coverage exec file -->
    <target name="runTestsAndGenerateExec" depends="startJavaService">
        <exec executable="java">
            <arg line="-javaagent:/home/wd/ApplicationTest/jacocoagent.jar=includes=com.wd.test.*,output=file,destfile=/home/wd/ApplicationTest/coverage.exec -cp /home/wd/ApplicationTest/junit-4.10.jar:/home/wd/ApplicationTest/JunitClass:/home/wd/ApplicationTest/JUTest.jar org.junit.runner.JUnitCore com.wd.test.JUTest"/>
        </exec>
    </target>

    <!-- Target to generate JaCoCo report -->
    <target name="generateReport" depends="runTestsAndGenerateExec">
        <exec executable="java">
            <arg line="-jar /home/wd/jacoco-0.8.10/lib/jacococli.jar report /home/wd/ApplicationTest/coverage.exec --classfiles /home/wd/ApplicationTest/JunitClass --sourcefiles /home/wd/ApplicationTest/Junit --html coverage_report --xml report.xml --encoding=utf-8"/>
        </exec>
    </target>
</project>

3、ant generateReport

  • 14
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值