2013-06-01 2 views
1

Maven을 사용하여 로컬 Jenkins 서버에서 코드 커버리지를 설정하려고했습니다. 내 검사가 보험 보상 보고서에 포함되지 않은 것으로 보입니다.Cobertura 코드 커버리지가 잘못되었습니다.

나는 내 pom.xml 파일에 다음이 : 나는

<plugin> 
    <!-- Separates the unit tests from the integration tests. --> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <configuration> 
     <skip>true</skip> 
     <trimStackTrace>false</trimStackTrace> 
     </configuration> 
    <executions> 
     <execution> 
      <id>unit-tests</id> 
      <phase>test</phase> 
      <goals> 
       <goal>test</goal> 
      </goals> 
      <configuration> 
       <skip>false</skip> 
       <includes> 
        <include>**/*Test*.java</include> 
       </includes> 
       <excludes> 
        <exclude>**/*IT.java</exclude> 
       </excludes> 
      </configuration> 
     </execution> 

     <execution> 
      <id>integration-tests</id> 
      <phase>integration-test</phase> 
      <goals> 
       <goal>test</goal> 
      </goals> 
      <configuration> 
       <skip>false</skip> 
       <includes> 
        <include>**/*IT.java</include> 
       </includes> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

그리고 내 젠킨스 서버에

을 실행되어야 할 시험은 내가 다음이 나는 정의 경우 여기

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
     <artifactId>sonar-maven-plugin</artifactId> 
     <version>2.0</version> 
</plugin> 
<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
     <artifactId>cobertura-maven-plugin</artifactId> 
     <version>2.5.2</version> 
     <configuration> 
     <check> 
     <haltOnFailure>false</haltOnFailure> 
      <totalLineRate>85</totalLineRate> 
     </check> 
     <formats> 
      <format>xml</format> 
      <format>html</format> 
     </formats> 
     </configuration> 
     <executions> 
      <execution> 
       <id>clean</id> 
       <phase>pre-site</phase> 
       <goals> 
        <goal>clean</goal> 
       </goals> 
      </execution> 
      <execution> 
       <id>instrument</id> 
       <phase>site</phase> 
       <goals> 
        <goal>instrument</goal> 
        <goal>cobertura</goal> 
       </goals> 
      </execution> 
     </executions> 
</plugin> 

을하고있다 : 젠킨스 구성 : 소나 소나 이름 : 수중 음파 탐지기 지역 3.5.1 서버 URL : http://local host:9000

프로젝트 수준 : Cobertura Coverate 보고서를 게시 : XML 보고서 패턴 : **/대상/site.covertura/coverage.xml

하지만 "MVN의 cobertura : cobertura를"중 하나를 받는다는 작업을 실행할 때 또는 수중 음파 탐지기를보기 Jenkins의 모든 보도는 0 %로 내 단위 및 통합 테스트가 보이지 않는다고 생각합니다.

내 pom이 단위 테스트와 통합 테스트를 구분하는 방식에 문제가 있습니까?

답변

1

cobertura는 코드 적용 범위를보기 위해 통합 테스트를 조사 할 수 없습니다.

짧은 이야기를하려면 code coverage by integration tests with sonar 에서와 separating integration and unit tests

을 살펴보십시오 : 당신이 실행해야 jacoco 받는다는 플러그인 그것에 대한 또 다른 시험 두 가지 속성, 단위 테스트에 대한 하나를 설정하고 실행 누가 확실한 이러한 속성으로는 안전하지 못합니다.

그런 다음 분리 된 애플릿에서 결과를 소나에 표시 할 수 있습니다. 내 자신의 POM 파일에서

, 당신은 그 자체를 사용할 수 jacoco에 대한 일부 ". **/** 대상"젠킨스에서

  <properties> 
       <!-- Coverage and report --> 
       <jacoco.destFile.unit>${project.build.directory}/jacoco-unit.target</jacoco.destFile.unit> 
       <jacoco.destFile.it>${project.build.directory}/jacoco-it.target</jacoco.destFile.it> 
       <coverage.reports.dir>${project.build.directory}/coverage-reports</coverage.reports.dir> 
       <version.surefire>2.12.4</version.surefire> 

       <!-- Sonar --> 
       <sonar.jacoco.itReportPath>${jacoco.destFile.it}</sonar.jacoco.itReportPath> 
       <sonar.jacoco.reportPath>${jacoco.destFile.unit}</sonar.jacoco.reportPath> 
       <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin> 
       <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> 
      </properties> 


      <build> 
      .... 
      <plugins> 
       <!-- Jacoco configuration --> 
       <plugin> 
        <groupId>org.jacoco</groupId> 
        <artifactId>jacoco-maven-plugin</artifactId> 
        <version>0.6.0.201210061924</version> 
        <executions> 
         <execution> 
          <goals> 
           <goal>prepare-agent</goal> 
          </goals> 
          <configuration> 
           <propertyName>jacoco.argLine.unit</propertyName> 
           <destFile>${jacoco.destFile.unit}</destFile> 
          </configuration> 
         </execution> 
         <execution> 
          <id>pre-integration-test</id> 
          <phase>pre-integration-test</phase> 
          <goals> 
           <goal>prepare-agent</goal> 
          </goals> 
          <configuration> 
           <propertyName>jacoco.argLine.it</propertyName> 
           <destFile>${jacoco.destFile.it}</destFile> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
       <!-- And in the surefire and failsafe plugins you need to enable jacoco like this -> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>${version.surefire}</version> 
        <dependencies> 
         <dependency> 
          <groupId>org.apache.maven.surefire</groupId> 
          <artifactId>surefire-junit47</artifactId> 
          <version>${version.surefire}</version> 
         </dependency> 
        </dependencies> 
        <configuration> 
         <argLine>${jacoco.argLine.unit} 
          -Dfile.encoding=${project.build.sourceEncoding} -Xmx512m</argLine> 
         <forkMode>always</forkMode> 
         <parallel>classes</parallel> 
        </configuration> 
       </plugin--> 

       <!-- Play the /src/test/java/**IT.java with goal verify --> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-failsafe-plugin</artifactId> 
        <version>${version.surefire}</version> 
        <dependencies> 
         <dependency> 
          <groupId>org.apache.maven.surefire</groupId> 
          <artifactId>surefire-junit47</artifactId> 
          <version>${version.surefire}</version> 
         </dependency> 
        </dependencies> 
        <configuration> 
         <forkMode>pertest</forkMode> 
         <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory> 
         <argLine>${jacoco.argLine.it} 
          -Dfile.encoding=${project.build.sourceEncoding} -Xmx512m</argLine> 
        </configuration> 
        <executions> 
         <execution> 
          <id>integration-test</id> 
          <phase>integration-test</phase> 
          <goals> 
           <goal>integration-test</goal> 
          </goals> 
         </execution> 
         <execution> 
          <id>verify</id> 
          <phase>verify</phase> 
          <goals> 
           <goal>verify</goal> 
          </goals> 
         </execution> 
        </executions> 
       </plugin> 

, 당신이해야 설치 와 "postbuild"JaCoCo 플러그인에 대한 exec 파일의 경로

희망이 도움이 될 것입니다.

+0

좋아, 나는 (당신의 pom.xml 샘플처럼 보이게 만든다) JaCoco로 나의 cobertura 사용법을 대체하고 "mvn clean package"로 실행하려고 시도했지만 이제는 모든 테스트가 실행되지만 젠킨스에 대한 .exec 보고서는 생성되지 않는다. 표시 할 수 있습니다. – sonoerin

+0

보고서를 소나에서 보시겠습니까? "\ * \ */\ * \ *. dump"(exec 파일 경로)로 구성된 jacoco 플러그인입니까? – twillouer

+0

내가 뭘했는지는 확실치 않지만 지금은 작동하는 것 같습니다. Jenkins가 아니라 Sonar를 살펴보면 코드 커버리지에서 실행 된 테스트 (단위 및 통합)의 수를 볼 수 있습니다. 도와 주셔서 정말 감사합니다. 당신은 게시물을 통해 내가 일한 많은 자습서보다 도움이되었다! – sonoerin

관련 문제