You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置PIT测试以在覆盖率报告中排除指定包?

如何在PIT Maven插件中排除指定包生成测试覆盖率报告

没问题,要实现排除指定包的需求,你只需要在现有的PIT插件配置里添加<excludedClasses>节点,用来明确指定要排除的包或类即可。以下是调整后的完整配置示例:

<plugin>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-maven</artifactId>
    <version>1.3.0</version>
    <configuration>
        <targetClasses>
            <param>test.presentation.*</param>
            <param>test.service.impl.*</param>
        </targetClasses>
        <!-- 新增的排除配置 -->
        <excludedClasses>
            <!-- 这里替换成你要排除的包,支持通配符* -->
            <param>test.service.impl.excluded.*</param>
            <!-- 如果要排除单个类,直接写全类名:<param>test.service.impl.ExcludedClass</param> -->
        </excludedClasses>
        <targetTests>
            <param>test.App.ServletInitializerTest</param>
        </targetTests>
    </configuration>
</plugin>

关键说明:

  • <excludedClasses>和<targetClasses>一样,支持使用通配符*来匹配整个包下的所有类
  • 你可以添加多个<param>节点来排除多个包或类
  • 这个配置在你使用的1.3.0版本的pitest-maven插件中完全兼容,不需要升级版本

这样配置后,PIT在生成覆盖率报告时就会自动跳过你指定的排除包下的所有类啦。

内容的提问来源于stack exchange,提问作者Madiha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:15:47