【问题标题】:Gradle sonarqube not recognizing groovy testsGradle sonarqube 无法识别常规测试
【发布时间】:2017-05-18 02:19:08
【问题描述】:

我有一个使用 Java (JUnit) 和 Groovy (Spock) 实现的测试的多语言项目。

plugins {
    id "org.sonarqube" version "2.2.1"
}

apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'jacoco'

ext {
    spockVersion = '1.1-groovy-2.4-rc-3'
    groovyVersion = '2.4.7'
}

group = "at.softwarecraftsmen.poc"
version = "1.0.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testCompile "junit:junit-dep:4.11"

    testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
    testCompile "org.spockframework:spock-core:$spockVersion"
}

jacoco {
    toolVersion = "0.7.8+"
}

sonarqube {
    properties {
        //property 'sonar.tests', ["src/test/groovy", "src/test/java"]
        properties['sonar.tests'] += ["src/test/groovy"]
    }
}

在运行 sonarqube 任务时,它运行成功但报告Resource not found: at.softwarecraftsmen.poc.sonar.domain.DomainTesteeSpec。这是使用 Groovy 进行的 Spock 测试。

这是 Gradle 生成的完整日志输出:

$ ./gradlew clean jacoco sonarqube 
:clean
:compileJava
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes
:compileTestJava
:compileTestGroovy
:processTestResources UP-TO-DATE
:testClasses
:test
objc[4573]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
:jacocoTestReport
:sonarqube
Resource not found: at.softwarecraftsmen.poc.sonar.domain.DomainTesteeSpec
CodeNarc completed: (p1=0; p2=0; p3=0) 941ms
Resource not found: at.softwarecraftsmen.poc.sonar.domain.DomainTesteeUnitTest
File not found: at/softwarecraftsmen/poc/sonar/domain/DomainTestee.java
Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
File not found: at/softwarecraftsmen/poc/sonar/domain/DomainTestee.java
Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
BUILD SUCCESSFUL

添加properties['sonar.tests'] += ["src/test/groovy"] 并不能解决问题,只有来自src/test/java 的测试会正确报告。

------------------------------------------------------------
Gradle 3.3
------------------------------------------------------------

Build time:   2017-01-03 15:31:04 UTC
Revision:     075893a3d0798c0c1f322899b41ceca82e4e134b

Groovy:       2.4.7
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_71 (Oracle Corporation 25.71-b15)
OS:           Mac OS X 10.11.6 x86_64

【问题讨论】:

标签: gradle groovy sonarqube spock


【解决方案1】:

确保您已按照此处的说明在 Sonar 中安装了 Groovy 插件:

Integrate Spock's test with Sonar

您需要对 Sonar 实例进行管理员访问才能执行此操作。

【讨论】:

  • 我也有同样的问题。添加链接问题中提到的插件后,我看到测试出现在 SonarQube 中。但是,覆盖率数据不考虑 Spock 测试。
猜你喜欢
  • 2017-01-16
  • 1970-01-01
  • 2018-08-29
  • 2012-11-21
  • 1970-01-01
  • 2015-06-27
  • 1970-01-01
  • 1970-01-01
  • 2020-10-13
相关资源
最近更新 更多