0
votes

I am using Spek to test my Kotlin app. I would like to publish my tests report after Jenkins build. JUnit or TestNG would generate XML report which Jenkins can use to generate tests stats.

Does Spek generate such report? If so, how to configure my Gradle project to get it? If not, what are the other reporting options available?

2

2 Answers

1
votes

I haven't checked thoroughly my build directory. Since Spek is using JUnit 5 Platform Engine it will produce reports the same way as JUnit 5 would have done.

Indeed, after running ./gradlew clean build you can see the file here: ./build/reports/junit/TEST-spek.xml. I used Jenkins to publish JUnit XML report after build and it works fine.

If you'd like to change reports directory, you should configure it in Gradle build script as follows.

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

Source, JUnit 5 User guide: http://junit.org/junit5/docs/current/user-guide/#running-tests-build

0
votes

I am currently using JaCoCo with Coveralls to integrate my (multi-module) project after the CI build so I might have slightly mistakes for a mono-module (I have adapted it) build but this is part of my research.

The first thing that you need to do is configure your build.gradle in order to have your tests working is applying the Jacoco plugin to your gradle:

apply plugin: "jacoco"

And then you have to enable the output:

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

To generate the reports you can use: gradle test jacocoTestReport (Feel free to add just a jacocoTestReport to your already working command to build)

After the reports are generated now you have to send them to coveralls, this is done in a step after the compilation/testing has finished.

To send it to coveralls you need to add the gradle plugin for coveralls:

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

Create a rootReport task

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
    }
}

and add the kotlin sources for the coveralls task (only java support by default, Coveralls gradle plugin issue):

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

I stumbled upon a bug when doing it that needed this three lines when generating the jacocoRootReport but this is mostly for a multi module project (workaround source):

onlyIf = {
    true
}

The last step is configuring your CI tool to know where to find your coveralls token/properties (source). I personally have done it by adding environment variables and not coveralls.yml (it didn't work well).

And now you can add two steps to your after build:

gradlew jacocoRootReport coveralls

And you should see your reports in your coveralls page!

Jacoco and coveralls: https://nofluffjuststuff.com/blog/andres_almiray/2014/07/gradle_glam_jacoco__coveralls

Working example: https://github.com/jdiazcano/cfg4k/blob/master/build.gradle#L24