Skip to content

Adding scoverage to report Scala test coverage #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void setJavaVersion(javaVersionId) {
String featureBranchName = ""

//// gradle tasks that are executed
def gradleTasks = "--refresh-dependencies clean spotlessCheck pmdMain pmdTest spotbugsMain spotbugsTest allTests" // the gradle tasks that are executed on ALL projects
def mainProjectGradleTasks = "jacocoTestReport jacocoTestCoverageVerification" // additional tasks that are only executed on project 0 (== main project)
def gradleTasks = "--refresh-dependencies clean spotlessCheck pmdMain pmdTest check" // the gradle tasks that are executed on ALL projects
def mainProjectGradleTasks = "reportScoverage checkScoverage" // additional tasks that are only executed on project 0 (== main project)
// if you need additional tasks for deployment add them here
// NOTE: artifactory task with credentials will be added below
def deployGradleTasks = ""
Expand Down Expand Up @@ -99,7 +99,7 @@ if (env.BRANCH_NAME == "master") {


// test the project
stage("gradle allTests ${projects.get(0)}") {
stage("gradle check ${projects.get(0)}") {
// build and test the project
gradle("${gradleTasks} ${mainProjectGradleTasks}")
}
Expand Down Expand Up @@ -210,7 +210,7 @@ if (env.BRANCH_NAME == "master") {
}

// test the project
stage("gradle allTests ${projects.get(0)}") {
stage("gradle check ${projects.get(0)}") {

// build and test the project
gradle("${gradleTasks} ${mainProjectGradleTasks}")
Expand Down Expand Up @@ -326,15 +326,11 @@ def publishReports() {
// publish test reports
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/tests/allTests', reportFiles: 'index.html', reportName: "${projects.get(0)}_java_tests_report", reportTitles: ''])

// publish jacoco report for main project only
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/jacoco', reportFiles: 'index.html', reportName: "${projects.get(0)}_jacoco_report", reportTitles: ''])

// publish scoverage reports
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/scoverage', reportFiles: 'scoverage.xml', reportName: "${projects.get(0)}_scoverage_report", reportTitles: ''])
// publish pmd report for main project only
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/pmd', reportFiles: 'main.html', reportName: "${projects.get(0)}_pmd_report", reportTitles: ''])

// publish spotbugs report for main project only
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: projects.get(0) + '/build/reports/spotbugs', reportFiles: 'main.html', reportName: "${projects.get(0)}_spotbugs_report", reportTitles: ''])

}


Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ plugins {
id 'scala' // scala support
id 'maven-publish' // publish to a maven repo (local or mvn central, has to be defined)
id 'pmd' // code check, working on source code
id 'com.github.spotbugs' version '2.0.0' // code check, working on byte code
id 'com.diffplug.gradle.spotless' version '3.28.1'// code format
id "de.undercouch.download" version "3.4.3" // downloads plugin
id 'jacoco' // java code coverage plugin
id "org.sonarqube" version "2.8" // sonarqube
id 'org.scoverage' version '4.0.2' // Code coverage plugin for scala
id "com.github.maiflai.scalatest" version "0.26" // run scalatest without specific task
}

ext {
Expand All @@ -28,13 +29,11 @@ group = 'com.github.ie3-institute'
description = 'simbench4ie3'
version = '1.0-SNAPSHOT'

apply from: scriptsLocation + 'tests.gradle'
apply from: scriptsLocation + 'pmd.gradle'
apply from: scriptsLocation + 'spotbugs.gradle'
apply from: scriptsLocation + 'spotless.gradle'
apply from: scriptsLocation + 'checkJavaVersion.gradle'
apply from: scriptsLocation + 'tscfg.gradle' // config tasks
apply from: scriptsLocation + 'jacoco.gradle' // jacoco java code coverage
apply from: scriptsLocation + 'scoverage.gradle'

repositories {
jcenter() //searches in bintray's repository 'jCenter', which contains Maven Central
Expand Down Expand Up @@ -79,6 +78,8 @@ dependencies {
testCompile "org.scalatest:scalatest_${scalaVersion}:3.0.8"
testRuntime "org.pegdown:pegdown:1.6.0" // HTML report for scalatest
compile 'org.mockito:mockito-core:+' // mocking framework
scoverage "org.scoverage:scalac-scoverage-plugin_${scalaVersion}:1.4.1"
scoverage "org.scoverage:scalac-scoverage-runtime_${scalaVersion}:1.4.1"

// config //
implementation 'com.typesafe:config:+'
Expand Down
71 changes: 0 additions & 71 deletions gradle/scripts/jacoco.gradle

This file was deleted.

13 changes: 13 additions & 0 deletions gradle/scripts/scoverage.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Scala code coverage gradle plugin see https://github.com/scoverage/gradle-scoverage#configuration and
* https://github.com/scoverage/gradle-scoverage/issues/109 for details
*/
scoverage {
scoverageVersion = '1.4.1'
scoverageScalaVersion = '2.13.1'
coverageOutputHTML = false
coverageOutputXML = true
coverageOutputCobertura = false
minimumRate = 0.6 // minimum code coverage
coverageDebug = false
}
13 changes: 4 additions & 9 deletions gradle/scripts/sonarqube.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sonarqube {
properties {
// todo CK enable accordingly!
// general stuff
property 'sonar.projectName', 'simbench4ie3' // project name
property 'sonar.verbose', 'true' // verbose mode
Expand All @@ -25,12 +24,8 @@ sonarqube {
"build/reports/spotbugs/main.xml",
"build/reports/spotbugs/test.xml"] // Comma-delimited list of paths to reports from SpotBugs
// scala specific stuff
//property 'sonar.scala.coverage.reportPaths', ''//todo enable when scoverage gradle plugin is available for scala 2.13
property 'sonar.scala.coverage.reportPaths', 'build/reports/scoverage/scoverage.xml'

// groovy specific stuff
property 'sonar.groovy.jacoco.reportPath', 'build/jacoco/test.exec' // unit tests reports dir
/// integration tests reports dir (if any)
property 'sonar.groovy.jacoco.itReportPath', 'build/jacoco/allTests.exec'
property 'sonar.groovy.binaries', 'build/classes/groovy' // groovy binaries

// remove auto generated SimonaConfig file from analysis
Expand All @@ -43,7 +38,7 @@ project.tasks["sonarqube"].dependsOn "pmdMain"
project.tasks["sonarqube"].dependsOn "pmdTest"
project.tasks["sonarqube"].dependsOn "spotbugsMain"
project.tasks["sonarqube"].dependsOn "spotbugsTest"
project.tasks["sonarqube"].dependsOn "allTests"
project.tasks["sonarqube"].dependsOn "check"

project.tasks["sonarqube"].dependsOn "jacocoTestReport"
project.tasks["sonarqube"].dependsOn "jacocoTestCoverageVerification"
project.tasks["sonarqube"].dependsOn "reportScoverage"
project.tasks["sonarqube"].dependsOn "checkScoverage"
21 changes: 0 additions & 21 deletions gradle/scripts/spotbugs.gradle

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/scripts/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spotless {

// removes unnecessary whitespace, indents with tabs and ends on new line for gradle, md and gitignore files and config-XMLs
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore', 'configs/**'
target '**/*.md', '**/.gitignore', 'configs/**'
trimTrailingWhitespace()
indentWithTabs()
endWithNewline()
Expand Down
28 changes: 0 additions & 28 deletions gradle/scripts/tests.gradle

This file was deleted.