簡體   English   中英

如何從android項目中的jacoco測試覆蓋率報告中排除方法

[英]How do i exclude a method from jacoco test coverage report in android project

我檢查了Jacoco github ans瀏覽了一些Stack Overflow問題。 通過注釋不支持最高版本0.7.9的jacoco過濾方法,僅支持整個類。 現在0.8.0和0.8.1已經發布。 這些版本中是否添加了此功能? 我檢查了jacoco的變化歷史。

https://github.com/jacoco/jacoco/releases

但是在最新版本中看不到與過濾相關的任何內容。 但是仍然想確認某人是否實現了這一目標以及如何實現?

我找到了如何從覆蓋率報告中排除靜態方法的解決方案。

  1. 用靜態類包裝它
  2. 排除配置中的靜態類

示例java代碼:

private static class Document {
    private static org.w3c.dom.Document createDocument() {
        try {
            final javax.xml.parsers.DocumentBuilderFactory factory =
                    javax.xml.parsers.DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
            final javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.newDocument();
        } catch (javax.xml.parsers.ParserConfigurationException ex) {
            return null;
        }
    }
}

示例排除配置:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.2</version>
  <executions>
    <execution>
      <id>prepare-agent</id>
      <goals>
        <goal>prepare-agent</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <excludes>
      <exclude>**/Xml$Document.class</exclude>
    </excludes>
  </configuration>
</plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM