maven test 集成jacoco

1.框架:

代码框架: spring boot
测试框架: junit-4(为spring-boot-test中自带版本(高版本如:2.3.4.RELEASE 是junit-5))

2.pom文件配置

        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.4</version>
        </dependency>
        <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.4</version>
                <configuration>
<!--                    //统计的包-->
                    <includes>
                        <include>com/iwanvi/**</include>
                    </includes>
<!--                    //排除的包-->
                    <excludes>
                        <!--排除的包-->
                        <exclude>com/xxx/comm/utils/**</exclude>
                        <exclude>com/xxx/common/annotation/**</exclude>
                    </excludes>
                </configuration>
                <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>

3.测试代码

   @Test
    public void demo() throws Exception {
        System.out.println(port);
        ResponseEntity<String> responseEntity = restTemplate.getForEntity("/iqiyi/pullMsg/book/list"
                , String.class, "");
        System.out.println(responseEntity.getBody());
        MvcResult mvcResult = mockMvc.perform(
                MockMvcRequestBuilders.get("/iqiyi/pullMsg/book/list")
                        .param("identity", "11111")
                        .param("lastUpdateTime", "22"))
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andDo(MockMvcResultHandlers.print())
                .andReturn();
        System.out.println(mvcResult.getResponse().getContentAsString());
    }

4.运行

在这里插入图片描述
运行后再target-site-jacoco中查看index.html

在这里插入图片描述
备注:pom中可配置覆盖率监控并设置阈值,在jenkins部署可一同使用,可自行某度查询

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值