JaCoCo use statistical interface test code coverage

Do interface testing, very often hear, your interface test coverage is how much? A lot of people will answer 80% how you count, he said, covering 80% of the demand. The answer is no mistake, but one-sided, we should not only consider the coverage of the coverage needs, as well as business scene coverage, coverage of the interface, such as code coverage, code coverage This article describes the interface testing. Then we look at how are implemented.

        1, set up the environment

        1.1 build ant environment

            https://ant.apache.org/bindownload.cgi

        I downloaded version 1.10.7, this is because each version corresponds to the version of java is not the same, the official website of ant presentations, download the zip package, and then decompress it, then go to configure the environment variables, I use mac configuration, open: vi .bash_profile

        

export ANT_HOME=/Users/lileilei/Downloads/apache-ant-1.10.7

export PATH=$PATH:.:${ANT_HOME}/bin

        Once configured source .bash_profile take effect immediately

    

    

        Here, we have set up our ant environment.

        1.2 download JaCoCo.

            Download: https://www.jacoco.org/jacoco/

        After the download is complete, you can extract.

       Built above the required environment.

       2.ant ​​the build configuration file

           By build.xml pull to reach specific configuration file as follows:

     

<?xml version="1.0" encoding="utf-8"?>
<project name="plate_id_sample_service" xmlns:jacoco="antlib:org.jacoco.ant">
    <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
        <classpath path="/Users/lileilei/Downloads/jacoco-0.8.5/lib/jacocoant.jar"/>
    </taskdef>
    <target name="report">
        <jacoco:report>
            <executiondata>
                <file file="jacoco.exe"/>
            </executiondata>

            <structure name="pan">
                <!-- 可以按软件功能模块设置多个group,方便在report中查看 -->
                        <-!. class file path, can be placed on a client ->
                    <classfiles>
                <Group name = "PAN">
                        <fileset dir="/Users/lileilei/Desktop/plan/target/classes"/>
                    </classfiles>
                    <sourcefiles encoding="utf-8">
                        <!--源代码路径,可以放在客户端-->
                        <fileset dir="/Users/lileilei/Desktop/plan/src/main/java" />
                    </sourcefiles>
                </group>
            </structure>

            <!-- report文件保存地址 -->
            <html destdir="report"   encoding="utf-8"/>

        </jacoco:report>
    </target>
</project>

 


 

       This is a complete configuration file, I added a good place to comment on the configuration, you can set according to their needs.

        Then to start the service under test to be tested, and here I start with a jar of service, start-up mode.

            

java -javaagent:/Users/lileilei/Downloads/jacoco-0.8.5/lib/jacocoagent.jar=dumponexit=true,destfile=jacoco.exe -jar demo-2.0.6.RELEASE.jar

          It should javaagent, here is jacoco's agent, need to replace their path can be.

            After the startup is complete, we can begin testing,

            swgger2 I use a simple interface test, after obtaining coverage.

            

在build.xml目录,使用ant获取jacoco.exe然后用 ant report产生测试报告

            Open test reports,

        In this way, we get to the full amount of code coverage testing interface. We can open each category to obtain coverage for each function.

        In fact, the real coverage, we also need to consider the incremental code coverage. Here a brief introduction to do a full coverage amount of code. Start a discussion, we can continue to explore.

        We are here to provide an interface to statistically test coverage. Of course there are other ways we can go to explore their own needs.

        

            We need to be clear, to provide a reasonable solution.

            Reasonable plan to address the reasonable needs.

            Reasonable control, the reasonable control of time.

            Clear thinking, good at solving problems.

            Ideas program, depending on the practice.

            A lot of exercise in order to quick thinking.

            Behind closed doors, rigid thinking too hard.

            Accumulated bit by bit, the achievements of a bright tomorrow.

 

    Watch Sons of Thunder said the test

    

 

Guess you like

Origin www.cnblogs.com/leiziv5/p/11875844.html