0

我正在使用 Spek 测试我的 Kotlin 应用程序。我想在 Jenkins 构建后发布我的测试报告。JUnit 或 TestNG 会生成 Jenkins 可以用来生成测试统计信息的 XML 报告。

Spek 会生成这样的报告吗?如果是这样,如何配置我的 Gradle 项目来获取它?如果没有,还有哪些其他可用的报告选项?

4

2 回答 2

1

我还没有彻底检查我的build目录。由于 Spek 使用的是 JUnit 5 Platform Engine,它会以与 JUnit 5 相同的方式生成报告。

确实,运行后./gradlew clean build你可以在这里看到文件:./build/reports/junit/TEST-spek.xml. 我使用 Jenkins 在构建后发布 JUnit XML 报告,它工作正常。

如果您想更改报告目录,您应该在 Gradle 构建脚本中配置它,如下所示。

junitPlatform {
    reportsDir file("$buildDir/your/path")
    filters {
        engines {
            include 'spek'
        }
    }
}

来源,JUnit 5 用户指南:http: //junit.org/junit5/docs/current/user-guide/#running-tests-build

于 2017-03-08T13:04:24.213 回答
0

我目前正在使用JaCoCoCoveralls在 CI 构建之后集成我的(多模块)项目,因此对于单模块(我已经对其进行了调整)构建,我可能会有些错误,但这是我研究的一部分。

您需要做的第一件事是配置您的 build.gradle 以使您的测试正常工作,将 Jacoco 插件应用到您的 gradle:

apply plugin: "jacoco"

然后你必须启用输出:

jacocoTestReport {
    group = "Report"
    reports {
        xml.enabled = true
        csv.enabled = false
        html.destination "${buildDir}/reports/coverage"
    }
}

要生成您可以使用的报告:(请gradle test jacocoTestReport随意将 jacocoTestReport 添加到您已经工作的命令中以进行构建)

现在生成报告后,您必须将它们发送到工作服,这是在编译/测试完成后的一个步骤中完成的。

要将其发送到工作服,您需要为工作服添加 gradle 插件:

plugins {
    id 'com.github.kt3k.coveralls' version '2.7.1'
}

创建一个 rootReport 任务

task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
    dependsOn = subprojects.test
    sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
    classDirectories =  files(subprojects.sourceSets.main.output)
    executionData = files(subprojects.jacocoTestReport.executionData)
    reports {
        html.enabled = true
        xml.enabled = true
        csv.enabled = false
    }
}

并为工作服任务添加 kotlin 源代码(默认情况下仅支持 java,Coveralls gradle 插件问题):

coveralls {
    sourceDirs += ['src/main/kotlin']
}

我在生成 jacocoRootReport 时偶然发现了一个需要这三行的错误,但这主要用于多模块项目(解决方法源):

onlyIf = {
    true
}

最后一步是配置您的 CI 工具以了解在哪里可以找到您的工作服令牌/属性()。我个人是通过添加环境变量而不是添加环境变量来完成的coveralls.yml(效果不佳)。

现在您可以在构建后添加两个步骤:

gradlew jacocoRootReport coveralls

您应该在工作服页面中看到您的报告!

Jacoco 和工作服:https ://nofluffjuststuff.com/blog/andres_almiray/2014/07/gradle_glam_jacoco__coveralls

工作示例:https ://github.com/jdiazcano/cfg4k/blob/master/build.gradle#L24

于 2017-02-28T22:56:39.563 回答