cobertura 는 정적 코드 커버리지(static code coverage) 툴로 뜻은 스페인어로 coverage라고 한다.

 

정적 코드 커버리지는 자동화된 테스트 코드가 전체 코드중 어느 정도를 커버하고 있는지 분석해 주는 툴이다. 

 

코드중 테스트 비율을 바로 알수 있으므로 품질 향상에 도움을 주며 비슷한 제품으로는 상용으로는 아틀라시안의 clover 가 있다.

 

C/C++ 사용 시절에도 커버리지 테스트는 존재했었다. 이때는 자동화된 테스트가 없던 시절이라 static code coverage 가 아닌 runtime 에 호출되는 함수를 분석해서 커버리지를 확인하였다.

사용해 본 제품은 IBM에 인수된 래쇼날 사의 Purify 제품군인 Pure Coverage 였는데 엄청난 고가의 솔루션이었다. 오픈소스로 이런 커버리지 툴까지 나오는 거 보니 개발자 입장에서 좋은 건지 아닌지 잘 판단이 서지 않는다.

 

그럼 간단하게 cobertura 사용법을 알아 보자.

maven 과 연동

reporting 항목에 추가하면 된다. 

<reporting>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.6</version>
      </plugin>
    </plugins>
  </reporting>
XML

 

Goal

명시적으로 cobertura 관련 골을 실행해도 되며 reporting phase 이므로 site 를 실행해도 된다.

GoalReport?Description
cobertura:checkNoCheck the Last Instrumentation Results.
cobertura:cleanNoClean up rogue files that cobertura maven plugin is tracking.
cobertura:coberturaYesInstruments, Tests, and Generates a Cobertura Report.
cobertura:dump-datafileNoCobertura Datafile Dump Mojo
cobertura:helpNoDisplay help information on cobertura-maven-plugin.
Call
  mvn cobertura:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
cobertura:instrumentNoInstrument the compiled classes.

 

Ref