2017-07-16 303 views
1

我正在使用最新的SonarQube 6.4,Jenkins 2.60.1,并且我有一个应用程序进行了一些测试。在使用coverage插件在eclipse中运行应用程序后,我可以在测试覆盖率中看到大约90%。当我使用Jenkins构建我的应用程序时,我的问题开始,然后SonarQube显示结果,但测试覆盖率始终为空。我相信我错过了一些东西,所以任何帮助将不胜感激。jenkins构建作业后SonarQube中的测试覆盖率始终为空

这里是我的pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.example</groupId> 
<artifactId>demo</artifactId> 
<version>0.0.1-SNAPSHOT</version> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.4.RELEASE</version> 
    <relativePath /> <!-- lookup parent from repository --> 
</parent> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
    <sonar.host.url>http://localhost:9000</sonar.host.url> 
    <sonar.sources>src/main</sonar.sources> 
    <sonar.tests>src/test</sonar.tests> 
    <!-- Below property indicates the pattern of the test suite --> 
    <runSuite>**/*Suite.class</runSuite> 
    <!-- Sonar-JaCoCo properties --> 
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> 
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> 
    <sonar.jacoco.reportPaths>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPaths> 
    <sonar.language>java</sonar.language> 
    <jacoco.out.path>${session.executionRootDirectory}/target</jacoco.out.path> 
    <sonar.jacoco.itReportPath>${env.WORKSPACE}/target/${jacoco.out.file}</sonar.jacoco.itReportPath> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jdbc</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.mybatis.spring.boot</groupId> 
     <artifactId>mybatis-spring-boot-starter</artifactId> 
     <version>1.3.0</version> 
    </dependency> 

    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <scope>runtime</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> 
    <dependency> 
     <groupId>org.apache.logging.log4j</groupId> 
     <artifactId>log4j-core</artifactId> 
    </dependency> 


    <!-- https://mvnrepository.com/artifact/org.dbunit/dbunit --> 
    <dependency> 
     <groupId>org.dbunit</groupId> 
     <artifactId>dbunit</artifactId> 
     <version>2.5.3</version> 
    </dependency> 


    <dependency> 
     <groupId>com.github.springtestdbunit</groupId> 
     <artifactId>spring-test-dbunit</artifactId> 
     <version>1.3.0</version> 
    </dependency> 

    <!-- Adds Tomcat and Spring MVC, along others, jackson-databind included 
     transitively --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 


    <dependency> 
     <groupId>com.fasterxml.jackson.dataformat</groupId> 
     <artifactId>jackson-dataformat-xml</artifactId> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/com.jayway.restassured/spring-mock-mvc --> 
    <dependency> 
     <groupId>com.jayway.restassured</groupId> 
     <artifactId>spring-mock-mvc</artifactId> 
     <version>2.9.0</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-mongodb</artifactId> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/com.lordofthejars/nosqlunit-core --> 
    <dependency> 
     <groupId>com.lordofthejars</groupId> 
     <artifactId>nosqlunit-core</artifactId> 
     <version>1.0.0-rc.5</version> 
    </dependency> 


</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <configuration> 
       <reportsDirectory>${project.build.directory}/target/surefire-reports</reportsDirectory> 
       <argLine>${jacoco.agent.argLine}</argLine> 
      </configuration> 
     </plugin> 

     <plugin> 
      <artifactId>maven-failsafe-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>verify</id> 
        <goals> 
         <goal>integration-test</goal> 
         <goal>verify</goal> 
        </goals> 
        <configuration> 
         <argLine>${jacoco.agent.arg}</argLine> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

     <!-- Below plugin ensures the execution of test cases during maven build --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <configuration> 
       <includes> 
        <include>${runSuite}</include> 
       </includes> 
      </configuration> 
     </plugin> 
     <!-- Sonar-JaCoCo integration plugin --> 
     <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <version>0.7.9</version> 
      <configuration> 
       <destFile>${sonar.jacoco.reportPaths}</destFile> 
       <append>true</append> 
      </configuration> 
      <executions> 
       <execution> 
        <id>agent</id> 
        <goals> 
         <goal>prepare-agent</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

    </plugins> 
</build> 

这里是中邮步我的詹金斯性能(使用执行SonarQube扫描仪):

sonar.jdbc.dialect=mssql 
    sonar.projectKey=BillApplication 
    sonar.projectName=BillApplication 
    sonar.projectVersion=1.0 
    sonar.projectBaseDir=. 
    sonar.sources=. 
    sonar.binaries=target/classes 
    sonar.dynamicAnalysis=reuseReports 
    sonar.junit.reportsPath=build/test-reports/jacoco.exec 
    sonar.java.coveragePlugin=jacoco 
    sonar.core.codeCoveragePlugin=jacoco 
    sonar.junit.reportsPath=target/surefire-reports 
    sonar.jacoco.reportPath=target/coverage-reports/jacoco-ut.exec 

和最后的命令我使用的是:

clean org.jacoco:jacoco-maven-plugin:prepare-agent install -P 
    integration-tests --fail-at-end 

如果您需要其他配置,我会在此处发布。

+1

提供从詹金斯 – Suresh

回答

1

后期构建操作已弃用。

你是Maven项目,所以不需要明确提供属性。

As described in the docs,你的build命令后,你真正需要做的是这样的:$SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL

+1

控制台输出相关报道谢谢你的日志,它帮助我了解如何正确地运行它。我也改变了一些属性,最后它的工作。 – BillUser88