1

如何使用 spock 报告扩展 ( https://github.com/renatoathaydes/spock-reports ) 生成 html 报告。我已将依赖项添加到我的 build.gradle 文件中,据我所知,这是我唯一需要做的事情。但是当我在 Eclipse 上运行测试时,我找不到任何报告出现在任何地方。

这是我的 build.gradle 文件,spock 报告依赖关系在最后。

apply plugin: 'java-library'
apply plugin: 'groovy'

repositories {
    jcenter()
}

dependencies {
    api 'org.apache.commons:commons-math3:3.6.1'

    implementation 'com.google.guava:guava:22.0'

    testImplementation 'org.codehaus.groovy:groovy-all:2.4.11'

    testImplementation 'org.spockframework:spock-core:1.0-groovy-2.4'
    testImplementation 'junit:junit:4.12'

    testCompile( 'com.athaydes:spock-reports:1.3.1' ) {
        transitive = false // this avoids affecting your version of Groovy/Spock
    }
    testCompile 'org.slf4j:slf4j-api:1.7.13'
    testCompile 'org.slf4j:slf4j-simple:1.7.13'
}

编辑: build.gradle 文件是错误的。

我使用“gradle init --type java-library --test-framework spock”​​生成构建,效果很好,我添加了一些 groovy 类并且可以在 eclipse 上成功运行测试,但它给了我一个“无法推断 Groovy 类路径,因为当我尝试使用 gradle.build 时,在类路径 [...] 上找不到 Groovy Jar。

我将 Groovy 依赖项从“testImplementatiuon”更改为“compile”。它使项目可以从命令行编译和运行测试。这也生成了 spock 报告。

在 eclipse 上运行测试仍然不会生成测试报告。

我使用这个 build.gradle 文件从命令行构建了一个新项目:

apply plugin: 'groovy'
apply plugin: 'java-library'

repositories { jcenter() }

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.11'
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
    testCompile( 'com.athaydes:spock-reports:1.3.1' ) {
        transitive = false // this avoids affecting your version of Groovy/Spock
    }
    testCompile 'org.slf4j:slf4j-api:1.7.13'
    testCompile 'org.slf4j:slf4j-simple:1.7.13'
}

并在其上复制了相同的 groovy 文件。然后将项目导入eclipse。当我从 eclipse 运行测试(它生成 spock 报告)时,这个可以工作。我仍然不知道问题到底是什么,但我想我的问题已经解决了。

4

0 回答 0