Giter VIP home page Giter VIP logo

gradle-console-reporter's Introduction

gradle-console-reporter

Build Status Build status Coverage Stagus

Gradle plugin to report various kinds of summaries to console.

This plugin will aggregate test reports and show them to console.
It's useful when you use CI services that don't save artifacts.

Available reports

  • JUnit test report
  • JaCoCo coverage report
  • Cobertura coverage report

Usage

Getting started

Just apply the plugin in your build.gradle.

plugins {
    id 'com.github.ksoichiro.console.reporter' version '0.6.3'
}

Or

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.github.ksoichiro:gradle-console-reporter:0.6.3'
    }
}

apply plugin: 'com.github.ksoichiro.console.reporter'

Test report

When your tests fail, the plugin would print test failure details to the console.

$ ./gradlew test
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test

com.example.ATest > greet3 FAILED
    org.junit.ComparisonFailure at ATest.java:31

com.example.ATest > greet FAILED
    org.junit.ComparisonFailure at ATest.java:19

com.example.BTest > greet FAILED
    org.junit.ComparisonFailure at BTest.java:18

5 tests completed, 3 failed
:test FAILED
testsuite com.example.ATest:
  stdout:
    debug log in test2
    debug log
    debug log
    debug log in test
    debug log
  stderr:
    debug error log in test3
  testcase com.example.ATest > greet3: org.junit.ComparisonFailure: expected:<Hello[.]> but was:<Hello[]>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at com.example.ATest.greet3(ATest.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ...
	at java.lang.Thread.run(Thread.java:745)

  testcase com.example.ATest > greet: org.junit.ComparisonFailure: expected:<Hello[!]> but was:<Hello[]>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at com.example.ATest.greet(ATest.java:19)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ...
	at java.lang.Thread.run(Thread.java:745)

testsuite com.example.BTest:
  testcase com.example.BTest > greet: org.junit.ComparisonFailure: expected:<Bye[!]> but was:<Bye[]>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at com.example.BTest.greet(BTest.java:18)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ...
	at java.lang.Thread.run(Thread.java:745)
...

You can suppress stacktrace by configuring the plugin.
See configurations section for details.

JaCoCo coverage report

If you're using JaCoCo gradle plugin, you can see the coverage at the end of builds:

$ ./gradlew check

Coverage summary:
project1:                 72.2%
project2-with-long-name:   4.0%

BUILD SUCCESSFUL in 0s
9 actionable tasks: 1 executed, 8 up-to-date

Cobertura coverage report

If you're using stevesaliman/gradle-cobertura-plugin, you can see the coverage at the end of builds:

$ ./gradlew cobertura check

> Task :instrument
Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file

> Task :test
log4j:WARN No appenders could be found for logger (net.sourceforge.cobertura.coveragedata.TouchCollector).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

> Task :generateCoberturaReport
Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Report time: 198ms
Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Report time: 71ms

Coverage summary:
cobertura:  71.4%

BUILD SUCCESSFUL in 3s
7 actionable tasks: 7 executed

Tasks

reportTest

Print JUnit test report.
This task will be executed automatically after test task's failure by default, so you don't need to call it.

reportJacoco

Print JaCoCo coverage report.
This task will be executed automatically after jacocoTestReport task by default, so you don't need to call it.

reportCobertura

Print Cobertura coverage report.
This task will be executed automatically after cobertura task by default, so you don't need to call it.

Configurations

consoleReporter {
    junit {
        // Set this property to false if you don't need JUnit report.
        // Default is true.
        enabled true

        // Set this property to false if you want to see console report always.
        // Default is true.
        reportOnFailure true

        // Set this property to true if you want to see test summary.
        // Default is false.
        summaryEnabled true

        // Set this property to true if you want to see standard output.
        // Default is false.
        stdoutEnabled true

        // Set this property to true if you want to see standard error.
        // Default is false.
        stderrEnabled true

        // Set this property to false if you don't need stacktrace.
        // Default is true.
        stacktraceEnabled true

        // Set this property to false if you don't need colorized output.
        // Default is true.
        colorEnabled true

        // Set this property to false if you don't need source code between stacktrace.
        // Default is true.
        partialSourceInsertionEnabled true
    }

    jacoco {
        // Set this property to false if you don't need JaCoCo report.
        // Default is true.
        // Even if this is true, reporting will not work
        // without applying jacoco plugin.
        enabled true

        // Set this property to false if you want to see console report always.
        onlyWhenCoverageTaskExecuted true

        // Set this property to false if you want to see console report
        // just after each project's jacocoTestReport task.
        // If set to true, all reports will be shown at the end of builds.
        // Default is true.
        reportAfterBuildFinished true

        // Set this property to true if you want to treat a lack of the minimum coverage as an build error.
        // This property sees thresholdError property, and if the coverage has fallen below this value
        // the plugin will throw an exception to cause a build error.
        // Default is false.
        // If you set this to true, you should also set thresholdError property.
        failIfLessThanThresholdError false

        // Set this property to false if you don't like this plugin automatically changing some
        // property of jacoco plugin.
        // If this is set to true, the plugin will set some properties of jacoco plugin
        // to calculate coverage.
        // Default is true.
        autoconfigureCoverageConfig true

        // Set this property to your custom JacocoReport type task name, if you need.
        // Default is 'jacocoTestReport'.
        coverageTaskName 'jacocoTestReport'

        // Set this property to your JaCoCo report XML file.
        // Default is null, which means
        // ${project.buildDir}/reports/jacoco/test/jacocoTestReport.xml
        // will be parsed.
        reportFile

        // Set this property to a certain C0 coverage percentage.
        // When the coverage is greater than or equals to this value,
        // the coverage will be shown with green color.
        // Default is 90.
        thresholdFine 90

        // Set this property to a certain C0 coverage percentage.
        // When the coverage is greater than or equals to this value,
        // the coverage will be shown with yellow color.
        // (When the coverage is less than this value, result will be red.)
        // Default is 70.
        thresholdWarning 70

        // Set this property to a certain C0 coverage percentage.
        // When the coverage is less than this value and
        // failIfLessThanThresholdError property is set to true,
        // the build will fail.
        // Default is 0.
        thresholdError 0

        // Set this property if you want to customize build error message
        // when you use 'failIfLessThanThresholdError' feature.
        brokenCoverageErrorMessage "Coverage has fallen below the threshold in some projects."

        // Set this property to false if you don't need colorized output.
        // Default is true.
        colorEnabled true
    }

    cobertura {
        // Set this property to false if you don't need Cobertura report.
        // Default is true.
        // Even if this is true, reporting will not work
        // without applying stevesaliman/gradle-cobertura-plugin plugin.
        enabled true

        // Set this property to false if you want to see console report always.
        onlyWhenCoverageTaskExecuted true

        // Set this property to false if you want to see console report
        // just after each project's cobertura task.
        // If set to true, all reports will be shown at the end of builds.
        // Default is true.
        reportAfterBuildFinished true

        // Set this property to true if you want to treat a lack of the minimum coverage as an build error.
        // This property sees thresholdError property, and if the coverage has fallen below this value
        // the plugin will throw an exception to cause a build error.
        // Default is false.
        // If you set this to true, you should also set thresholdError property.
        failIfLessThanThresholdError false

        // Set this property to false if you don't like this plugin automatically changing some
        // property of cobertura plugin.
        // If this is set to true, the plugin will set some properties of cobertura plugin
        // to calculate coverage.
        // Default is true.
        autoconfigureCoverageConfig true

        // Set this property to your custom cobertura task name, if you need.
        // Default is 'generateCoberturaReport'.
        coverageTaskName 'generateCoberturaReport'

        // Set this property to your Cobertura report XML file.
        // Default is null, which means
        // ${project.buildDir}/reports/cobertura/coverage.xml
        // will be parsed.
        reportFile

        // Set this property to a certain C0 coverage percentage.
        // When the coverage is greater than or equals to this value,
        // the coverage will be shown with green color.
        // Default is 90.
        thresholdFine 90

        // Set this property to a certain C0 coverage percentage.
        // When the coverage is greater than or equals to this value,
        // the coverage will be shown with yellow color.
        // (When the coverage is less than this value, result will be red.)
        // Default is 70.
        thresholdWarning 70

        // Set this property to a certain C0 coverage percentage.
        // When the coverage is less than this value and
        // failIfLessThanThresholdError property is set to true,
        // the build will fail.
        // Default is 0.
        thresholdError 0

        // Set this property if you want to customize build error message
        // when you use 'failIfLessThanThresholdError' feature.
        brokenCoverageErrorMessage "Coverage has fallen below the threshold in some projects."

        // Set this property to false if you don't need colorized output.
        // Default is true.
        colorEnabled true
    }
}

License

Copyright 2015 Soichiro Kashima

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

gradle-console-reporter's People

Contributors

ksoichiro avatar sleberrigaud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gradle-console-reporter's Issues

It doesn't work with Gradle 5

$ ./gradlew jacocoTestReport

FAILURE: Build failed with an exception.

* What went wrong:
Could not find method execute() for arguments [] on task ':reportJacoco' of type com.github.ksoichiro.console.reporter.ReportJacocoTask.

thank you!

Thanks, great plugin! exactly what I wanted :)

Jacoco coverage reported as 0.0% on first run

It seems like the console reported always prints out 0.0% coverage on the first run in a clean environment.

Steps to produce:

  1. Delete any previous reports directory.
  2. Run ./gradlew jacocoTestReport
  3. Notice how the coverage summary says 0.0% coverage.
  4. Run ./gradlew jacocoTestReport again
  5. The correct coverage summary is now printed.

This makes it impossible to use it for CI integration as the tests there will always be run in a clean environment.

Version 0.6.0 not aviable on plugins.gradle.org

I tried to upgrade to version 0.6.0 which should be compatible with gradle 5.x but failed. Is there another maven repository where I can download the plugin?

Steps to reproduce

mkdir test

cd test

gradle wrapper

echo 'plugins {
    id "com.github.ksoichrio.console.reporter" version "0.6.0"
}
' > build.gradle

./gradlew test

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/emundo/Documents/Projekt/BMW/PPT/Code/test/build.gradle' line: 2

* What went wrong:
Plugin [id: 'com.github.ksoichrio.console.reporter', version: '0.6.0'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.github.ksoichrio.console.reporter:com.github.ksoichrio.console.reporter.gradle.plugin:0.6.0')
  Searched in the following repositories:
    Gradle Central Plugin Repository

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Type 'com.github.ksoichiro.console.reporter.ReportCoverageTask' property 'extension' is missing an input or output annotation

I am trying to run the console reporter on Jacoco coverage reports using Gradle 7.0.2

> Task :reportCoverage FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':reportCoverage' (type 'ReportCoverageTask').
  - Type 'com.github.ksoichiro.console.reporter.ReportCoverageTask' property 'extension' is missing an input or output annotation.

    Reason: A property without annotation isn't considered during up-to-date checking.

    Possible solutions:
      1. Add an input or output annotation.
      2. Mark it as @Internal.

    Please refer to https://docs.gradle.org/7.0.2/userguide/validation_problems.html#missing_annotation for more details about this problem.

Warnings for Gradle 4.5.1

When executed with Gradle 4.5.1 produces this warnings message:

> Task :jacocoTestReport
The TaskInternal.execute() method has been deprecated and is scheduled to be removed in Gradle 5.0. There are better ways to re-use task logic, see https://docs.gradle.org/4.5.1/userguide/custom_tasks.html#sec:reusing_task_logic.

Show branch coverage

Thanks for this helpful plugin!

Is it possible to show branch coverage instead of line/statement coverage?

I am using Jacoco and find the shown coverage percentage a bit misleading.

Color output for coverage does not seem to be working

I have attempted both using the default colorEnabled and explicitly setting it to true, but it appears that coverage output does not get any color applied:
screen shot 2018-10-05 at 10 32 27 am

config:

consoleReporter {
    jacoco {
        autoconfigureCoverageConfig false
        coverageTaskName "jacocoVariantDevReport"
        reportFile project.file("${buildDir}/reports/jacoco/jacocoVariantDevReport/jacocoVariantDevReport.xml")
        thresholdWarning 50
        colorEnabled true
    }
}

Task `reportJacoco` run on its own doesn't seem to use the config

When running the reportJacoco task directly, it doesn't seem to pick up the configuration for the report file if it has been modified.

Config:

consoleReporter {
    jacoco {
        autoconfigureCoverageConfig false
        coverageTaskName "jacocoVariantDevReport"
        reportFile project.file("${buildDir}/reports/jacoco/jacocoVariantDevReport/jacocoVariantDevReport.xml")
        thresholdWarning 50
        colorEnabled true
    }
}

If I run the configured coverage task name, the console report is correct:
screen shot 2018-10-05 at 10 32 27 am

If I then immediately run reportJacoco I get 0.0%:
screen shot 2018-10-05 at 11 13 28 am

./gradlew jacocoTestReport does not print coverage

I don't know why, but the jacocoTestReport task is the only task which does not print any coverage information. I tried with different configuration settings.

I can use the following workaround (using the settings in my build.gradle as written below):

./gradlew build
./gradlew jacocoTestReport
./gradlew build

Current settings in build.gradle look like:

jacoco {
    toolVersion = "0.8.2"
    // reportsDir = file("$buildDir/customJacocoReportDir")
}

consoleReporter {
    jacoco {
        reportAfterBuildFinished true
        onlyWhenCoverageTaskExecuted false
        reportFile new File("${project.buildDir}/reports/jacoco/test/jacocoTestReport.xml")
        coverageTaskName 'jacocoTestReport'
    }
}

jacocoTestReport {
    dependencies {
        test
    }
    reports {
        xml.enabled true
        csv.enabled false
        html.destination file("${buildDir}/jacocoHtml")
    }
}

jacoco {
    applyTo run
}

task applicationCodeCoverageReport(type:JacocoReport){
    executionData run
    sourceSets sourceSets.main
}
  • The first call to build will show a coverage of 0%, as no report has been generated yet
  • The call to jacocoTestReport will not output any coverage
  • The 2nd call to build will pick up the report as generated by jacocoTestReport and display the coverage:
localuser@localhost:~/repositories/butler$ ./gradlew build
...
Coverage summary:
butler:   0.0%

BUILD SUCCESSFUL in 23s
10 actionable tasks: 10 executed
localuser@localhost:~/repositories/butler$ ./gradlew jacocoTestReport

BUILD SUCCESSFUL in 1s
2 actionable tasks: 1 executed, 1 up-to-date
localuser@localhost:~/repositories/butler$ ./gradlew build

Coverage summary:
butler:  77.5%

BUILD SUCCESSFUL in 729ms
10 actionable tasks: 1 executed, 9 up-to-date
localuser@localhost:~/repositories/butler$ ./gradlew jacocoTestReport

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.