Exclude methods from code coverage with Cobertura

后端 未结 5 1662
情话喂你
情话喂你 2020-11-27 14:22

Is there a way to exclude code from inclusion into Cobertura coverage reports? We have some methods that should not be included in the coverage report and therefore not driv

5条回答
  •  独厮守ぢ
    2020-11-27 15:15

    Since 2.0 you can write your own @CoverageIgnore annotation.

    It will be recognized by Cobertura, which will avoid considering annotated methods (does not work on classes as far as I know).

    1. Create an empty annotation:
    public @interface CoverageIgnore {}
    
    1. Then annotate the methods you want to exclude from the reports:
    public class SomeClass {
        @CoverageIgnore
        public void foo(String baz) {
            // useless stuff
        }
    }
    

    Source: https://github.com/cobertura/cobertura/wiki/Coverage-Annotations

提交回复
热议问题