Coder Social home page Coder Social logo

radarsh / gradle-test-logger-plugin Goto Github PK

View Code? Open in Web Editor NEW
814.0 9.0 36.0 7.78 MB

A Gradle plugin for printing beautiful logs on the console while running tests

License: Apache License 2.0

Groovy 96.85% PowerShell 0.12% Java 2.50% Kotlin 0.53%
gradle groovy console gradle-plugin test logger ansi-colors colours hacktoberfest

gradle-test-logger-plugin's Introduction

Gradle Test Logger Plugin

Gradle Plugin Portal CircleCI branch AppVeyor branch Coveralls branch License Twitter Follow

A Gradle plugin for printing beautiful logs on the console while running tests.

Screenshots

Standard theme

Standard theme

Mocha theme

Mocha theme

Scroll down for more themes and customisation options or visit the screenshots page for more demos.

Usage

Using the plugins DSL

plugins {
    id 'com.adarshr.test-logger' version '4.0.0'
}

Using legacy plugin application

buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'com.adarshr:gradle-test-logger-plugin:4.0.0'
    }
}

apply plugin: 'com.adarshr.test-logger'

Compatibility matrix

Test logger version Minimum Gradle version
1.x 4.x
2.x 5.x
3.x 6.5
4.x 7.6

Configuration

The plugin registers an extension called testlogger (all lowercase and one word) at project level as well as for each task of type Test.

The following shows the complete default configuration applied when you configure nothing.

testlogger {
    theme 'standard'
    showExceptions true
    showStackTraces true
    showFullStackTraces false
    showCauses true
    slowThreshold 2000
    showSummary true
    showSimpleNames false
    showPassed true
    showSkipped true
    showFailed true
    showOnlySlow false
    showStandardStreams false
    showPassedStandardStreams true
    showSkippedStandardStreams true
    showFailedStandardStreams true
    logLevel 'lifecycle'
}

Project vs task level configuration

Settings configured at the project level can be overridden by redefining them at task level. Settings not defined at task level will inherit project level values. Consider the below configuration.

testlogger {
    theme 'mocha' // project level
    slowThreshold 5000
}

test {
    testlogger {
        theme 'standard-parallel' // task level
    }
}

In the above example, the effective theme will be standard-parallel and slowThreshold will be 5000 whereas rest of the settings will retain their default values.

Overriding settings at runtime

All the above settings can either be specified in build.gradle or be set at runtime using system properties or both. For instance, we could have theme set to mocha in the build file but it can be overridden to be standard at runtime by using -Dtestlogger.theme=standard on the command line. Since they are system properties we have a number of ways of specifying them including JAVA_OPTS and gradle.properties.

  • The convention used for determining the name of the system property is testlogger.<configuration setting>.
  • System property overrides will be applied after combining task and project level settings.
  • Specifying a system property override will apply the same setting for all tasks, regardless of any configuration defined in the build file.

Switch themes

testlogger {
    theme 'mocha'
}

The following themes are currently supported:

  1. plain - displays no colours or Unicode symbols
  2. standard - displays colours but no Unicode symbols
  3. mocha - similar to what Mocha's spec reporter prints, with colours and Unicode symbols
  4. plain-parallel - similar to the plain theme but supports parallel test execution
  5. standard-parallel - similar to the standard theme but supports parallel test execution
  6. mocha-parallel - similar to the mocha theme but supports parallel test execution

Hide exceptions

By default, the showExceptions flag is turned on. This shows why the tests failed including the location of the failure. Of course, you can switch off this slightly more verbose logging by setting showExceptions to false.

testlogger {
    showExceptions false
}

Hide exception stack traces

Sometimes it is useful to just see the exception message instead of the stack trace. This can be configured by setting showStackTraces to false.

testlogger {
    showStackTraces false
}

Hide exception causes

The default behaviour of the plugin is to print all the causes of the exception. If it is too verbose to your taste, you can turn it off by setting showCauses to false.

testlogger {
    showCauses false
}

Show full exception stack traces

Just like Gradle itself, by default only the last frame that matches the test class's name in a stack trace is printed. For vast majority of cases, that is sufficient. Sometimes, it is useful to remove this filtering in order to see the entirety of the stack trace. This can be done by setting showFullStackTraces to true.

testlogger {
    showFullStackTraces true
}

Define slow threshold

Tests that are too slow will have their duration logged. However, "slow" is a relative terminology varying widely depending on the type of tests being executed, environment, kind of project and various other factors. Therefore you can define what you consider as slow to suit your needs.

testlogger {
    slowThreshold 5000
}

The default value of slowThreshold is 2 seconds. So all tests that take longer than a second to run will have their actual execution time logged.

If you want to turn off the logging of time taken completely, simply set the threshold to a very large value.

Please note that in themes that support colours, the duration is displayed using a warning style if it is greater than half the slow threshold. For instance, if slowThreshold is 5 seconds any tests that take longer than 2.5 seconds to run would have their durations logged using a warning style and those that take longer than 5 seconds to run using an error style.

Hide summary

By default, a useful summary containing a breakdown of passing, failing and skipped tests along with the total time taken to execute all the tests is shown. Of course, you can disable this if you prefer a more succinct output.

testlogger {
    showSummary false
}

Show simple names

If you don't like seeing long, fully-qualified class names being used for displaying the test suite names, you can choose to show only simple names by setting the below flag to true.

testlogger {
    showSimpleNames true
}

Show standard streams

The display of standard output and error streams alongside the test logs can be controlled using the below configuration.

testlogger {
    showStandardStreams true
}

Filter standard streams

If the display standard output and error streams is enabled, it can often produce too much output to overwhelm anyone. Fortunately, we can filter this output based on the type of the test result.

testlogger {
    showStandardStreams true
    showPassedStandardStreams false
    showSkippedStandardStreams false
    showFailedStandardStreams true
}

All the three filter flags are enabled by default. In other words, the standard stream output is not filtered if showStandardStreams is enabled but none of the filter flags are configured.

If showStandardStreams is set to false, the filter flags don't have any effect.

Filter test results

Sometimes it is useful to hide test results of a certain type. For instance, if an application has hundreds of tests, the sheer volume of the output produced by passing tests could be enough to bury any valuable test failures. Similarly there might be a need to hide skipped tests or in rare instances even the failed ones.

We can perform test result filtering by using the below settings.

testlogger {
    showPassed false
    showSkipped false
    showFailed true
    showOnlySlow false
}

By default the flags showPassed, showSkipped and showFailed are turned on while showOnlySlow will be off. If you have chosen to display standard streams by setting showStandardStreams flag to true, any output produced by filtered out tests will not be displayed.

Change log level

By default, results are output at the standard lifecycle Gradle log level. This can be configured with logLevel. For example, the following will output the results even on runs with --quiet.

testlogger {
    logLevel 'quiet'
}

Relationship between testlogger and Test.testLogging

Where possible, the plugin's testlogger extension tries to react to equivalent properties of Gradle's Test.testLogging extension. However, if a value is explicitly configured under the testlogger extension, the plugin does not react to the corresponding property of Test.testLogging. The below table demonstrates this in more detail.

Property Test.testLogging value testlogger value Effective value
showStandardStreams true not configured true
showStandardStreams true false false
showStandardStreams false true true
showExceptions true not configured true
showExceptions true false false
showExceptions false true true
showStackTraces true not configured true
showStackTraces true false false
showStackTraces false true true
showFullStackTraces testLogging.exceptionFormat = FULL not configured true
showFullStackTraces testLogging.exceptionFormat = SHORT not configured false
showFullStackTraces testLogging.exceptionFormat = FULL false false
showFullStackTraces testLogging.exceptionFormat = SHORT true true
showCauses true not configured true
showCauses true false false
showCauses false true true

In other words, an explicitly configured testlogger property, despite it being false, takes precedence over any value of Test.testLogging.

Kotlin DSL

If you are using the Kotlin DSL, the syntax of testlogger extension DSL changes slightly. The following shows the default configuration properties using Kotlin DSL style.

testlogger {
    theme = ThemeType.STANDARD
    showExceptions = true
    showStackTraces = true
    showFullStackTraces = false
    showCauses = true
    slowThreshold = 2000
    showSummary = true
    showSimpleNames = false
    showPassed = true
    showSkipped = true
    showFailed = true
    showOnlySlow = false
    showStandardStreams = false
    showPassedStandardStreams = true
    showSkippedStandardStreams = true
    showFailedStandardStreams = true
    logLevel = LogLevel.LIFECYCLE
}

One gotcha about Kotlin DSL is that if you have subprojects that are trying to use a different testlogger setting compared to the parent project, the syntax changes slightly.

subprojects {

    apply {
        plugin("com.adarshr.test-logger")
    }

    configure<TestLoggerExtension> {
        theme = ThemeType.STANDARD
        showExceptions = true
        ...
    }
}

FAQ

Does it work on Windows?

Mostly. The standard and plain themes work out of the box but you might have to make a few modifications to your system settings to see Unicode symbols when using the mocha theme.

  1. Set or update JAVA_OPTS with the system property -Dfile.encoding=UTF-8
  2. Change the terminal code page to 65001 by executing chcp 65001

How to disable colours and Unicode symbols at runtime such as on Jenkins consoles?

You can switch off ANSI control characters and Unicode symbols by adding --console=plain to your Gradle command line.

Does it support parallel test execution?

Yes. You will need to switch to a suitable parallel theme though. This can be one of plain-parallel, standard-parallel or mocha-parallel. The parallel themes are specially designed to work with a setting of maxParallelForks greater than 1. They achieve this by sacrificing the ability to group tests and thus some readability is lost.

Can this plugin co-exist with junit-platform-gradle-plugin?

Due to certain unknown reasons, junit-platform-gradle-plugin is incompatible with gradle-test-logger-plugin. If you are still using junit-platform-gradle-plugin, it might be worth noting that this plugin was deprecated in JUnit Platform 1.2 and removed from JUnit Platform 1.3.

The test logger plugin however, is fully compatible with the Gradle native way of using JUnit 5.

gradle-test-logger-plugin's People

Contributors

aalmiray avatar baynezy avatar dependabot-preview[bot] avatar dependabot[bot] avatar goooler avatar grimmjo avatar mithomas avatar rabidaudio avatar radarsh avatar theosotr 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  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  avatar  avatar  avatar  avatar  avatar

gradle-test-logger-plugin's Issues

Refresh screenshots

Refresh screenshot animations to demonstrate recent capabilities. Also consider adding screenshot images.

A couple usability suggestions

I like the plugin but I ran into a couple things that would be nice to have (especially during first-time use):

  1. Small but took a minute to find - I am used to camelCase with Java and Groovy names, so I started out with testLogger eventually realized the L is not capitalized. Maybe make both valid or just point out the difference in the documentation.
  2. My projects use parallel tests which caused the theme to fail. It appears to know that I am using parallel testing - if this is the case, could you not switch to the parallel version of the same theme and provide a warning log that this change was made.

These are just suggestions - feel free to close this issue if they are not something you want to pursue.

Could not create an instance of type com.adarshr.gradle.testlogger.TestLoggerExtension_Decorated.

Dear Developers,

I tried to apply this plugin to my project, but unfortunately I got the following exception :

  • Exception is:
    org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'com.adarshr.test-logger', version: '1.1.2']
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:178)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:130)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:126)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:510)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:90)
    at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:42)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
    at org.gradle.initialization.DefaultGradleLauncher$2.run(DefaultGradleLauncher.java:125)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:122)
    at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:99)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:93)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:93)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:82)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:78)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:48)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:170)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:33)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
    Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'com.adarshr.test-logger']
    at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:160)
    at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:112)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$5.run(DefaultPluginRequestApplicator.java:132)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:166)
    ... 49 more
    Caused by: org.gradle.internal.reflect.ObjectInstantiationException: Could not create an instance of type com.adarshr.gradle.testlogger.TestLoggerExtension_Decorated.
    at org.gradle.internal.reflect.DirectInstantiator.newInstance(DirectInstantiator.java:51)
    at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36)
    at org.gradle.api.internal.plugins.DefaultConvention.create(DefaultConvention.java:106)
    at com.adarshr.gradle.testlogger.TestLoggerPlugin.apply(TestLoggerPlugin.groovy:13)
    at com.adarshr.gradle.testlogger.TestLoggerPlugin.apply(TestLoggerPlugin.groovy)
    at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(ImperativeOnlyPluginApplicator.java:35)
    at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(RuleBasedPluginApplicator.java:44)
    at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:144)
    ... 52 more
    Caused by: java.lang.NoClassDefFoundError: Lorg/gradle/api/logging/configuration/ConsoleOutput;
    at com.adarshr.gradle.testlogger.TestLoggerExtension.$getStaticMetaClass(TestLoggerExtension.groovy)
    at com.adarshr.gradle.testlogger.TestLoggerExtension.(TestLoggerExtension.groovy)
    at com.adarshr.gradle.testlogger.TestLoggerExtension_Decorated.(Unknown Source)
    at org.gradle.internal.reflect.DirectInstantiator.newInstance(DirectInstantiator.java:49)
    ... 59 more
    Caused by: java.lang.ClassNotFoundException: org.gradle.api.logging.configuration.ConsoleOutput
    ... 63 more

Do you have any ideas about that ?

Bad encoding on standard and mocha themes when printing to Eclipse's console

When using the plain theme, the output is fine:

com.toys.OperationTest

  Test testTimes() FAILED

  org.opentest4j.AssertionFailedError: TIMES should multiply 2 and 3 to be 6 ==> expected: <5.0> but was: <6.0>
      at com.toys.OperationTest.testTimes(OperationTest.java:20)

  Test testPlus() PASSED

FAILURE: Executed 2 tests in 853ms (1 failed)

However, when using standard or mocha the output is:

�[0K�[1mcom.toys.OperationTest�[m

�[0K�[1m  Test �[22mtestTimes()�[31m FAILED�[31m

  org.opentest4j.AssertionFailedError: TIMES should multiply 2 and 3 to be 6 ==> expected: <5.0> but was: <6.0>
      at com.toys.OperationTest.testTimes(OperationTest.java:20)
�[m
�[0K�[1m  Test �[22mtestPlus()�[32m PASSED�[m

�[0K�[1;31mFAILURE: �[39mExecuted 2 tests in 817ms (1 failed)�[m

The run configuration for the gradle test command specifies UTF-8 encoding.

Using Eclipse 4.9

Test logger should use test logger

This plugin project should itself use the plugin during testing. The Circle CI config should be updated to run tests with --console=plain after this.

Feature: suppress logging output for successful tests

I'm not sure if this is within this project's remit, or if there's a better way to do it, but:

When a test fails I wish I'd increased app (not test) logging verbosity. But when tests are good that logging is verbose and very cluttery. Could gradle-test-logger optionally capture the running program's output (I assume slf4j is outputting to stdout) and only output it if the test fails?

JUnit5 Gradle Plugin interferes with this one

Hi!

Here's our story: a teammate and I were trying to get your plugin working on our project. It took us a good amount of time, but we figured out why it wasn't working: the junit-platform-gradle-plugin was preventing most of the output from this plugin.

While there is a small blurb in the documentation about that plugin being deprecated, we still had it in our build.gradle because, I think, of some copy-pasta from older JUnit5 documentation.

It may be worth adding a note to your README that this might cause problems.

Regardless, this plugin works great! Thanks for the work you put in to it.

Add ability to hook it into additional Test type tasks

In some of the projects I work on, they split tests up with additional source sets to allow the task to incrementally run (i.e. unitTest, integrationTest, systemTest). It would be nice if I could hook this into these other test tasks.

testlogger { testTasks ['test', 'integrationTest', 'systemTest'] }

Or optionally, hook into any Test type task by default:
tasks.withType(Test)

Do not print empty suites with no tests

If a suite has no tests in it, it should not be printed. To reproduce, use Gradle test filtering and select a single test. Notice how all the other suites are also printed even though no tests within them are executed.

Add option to display STDOUT

I like this plugin, but only wish it had an option to display the standard output stream.

Granted, I could add the standard Gradle-i or --info switch, but adds too much extra info. Is there a middle ground?

Use of testLogger.showStandardStreams can lead to confusion

Hello there,

Thank you very much for this nice plugin! We really need user-friendly tools like yours in the Java community!

I was looking for a way to enable printing of stdout/stderr of my tests, and everywhere I googled I was pointed at gradle Test task's testLogging.showStandardStreams option.

But because I use gradle-test-logger-plugin, this wasn't working. After some time it dawned on me that the issue may come from the plugin, and I was able to confirm this and then go into the documentation and see that with this plugin, one should actually use testLogger.showStandardStreams instead.

Since this is a bit confusing, I would like to suggest that support for reading from testLogging.showStandardStreams also be added. I believe that would a lot more predictable for people with existing test configurations, and hopefully no other users would lose a few minutes banging their heads against this small issue.

Thanks for your time! 🙏

Develop branch: No such property: displayName for class: org.gradle.api.internal.tasks.testing.DecoratingTestDescriptor

I'm using gradle 4.6 and JUnit 5.

If I run tests using 8a70dcd I get the stacktrace below. If I go a few commits back to a9dfde0 it is fine.

No such property: displayName for class: org.gradle.api.internal.tasks.testing.DecoratingTestDescriptor
groovy.lang.MissingPropertyException: No such property: displayName for class: org.gradle.api.internal.tasks.testing.DecoratingTestDescriptor
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
        at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:66)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
        at com.adarshr.gradle.testlogger.theme.StandardTheme.testText(StandardTheme.groovy:20)
        at com.adarshr.gradle.testlogger.theme.Theme$testText$1.call(Unknown Source)
        at com.adarshr.gradle.testlogger.logger.TestEventLogger.afterTest(TestEventLogger.groovy:62)
        at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:42)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:230)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:149)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
        at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:324)
        at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:234)
        at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:140)
        at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
        at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
        at com.sun.proxy.$Proxy93.afterTest(Unknown Source)
        at org.gradle.api.internal.tasks.testing.results.TestListenerAdapter.completed(TestListenerAdapter.java:50)
        at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:42)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:230)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:149)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
        at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:324)
        at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:234)
        at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:140)
        at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
        at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
        at com.sun.proxy.$Proxy95.completed(Unknown Source)
        at org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor.completed(StateTrackingTestResultProcessor.java:71)
        at org.gradle.api.internal.tasks.testing.results.AttachParentTestResultProcessor.completed(AttachParentTestResultProcessor.java:56)
        at sun.reflect.GeneratedMethodAccessor114.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.dispatch.FailureHandlingDispatch.dispatch(FailureHandlingDispatch.java:29)
        at org.gradle.internal.dispatch.AsyncDispatch.dispatchMessages(AsyncDispatch.java:133)
        at org.gradle.internal.dispatch.AsyncDispatch.access$000(AsyncDispatch.java:34)
        at org.gradle.internal.dispatch.AsyncDispatch$1.run(AsyncDispatch.java:73)
        at org.gradle.internal.operations.BuildOperationIdentifierPreservingRunnable.run(BuildOperationIdentifierPreservingRunnable.java:39)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
        at java.lang.Thread.run(Thread.java:745)

Print failure reason and stacktrace

Test failures should print more detail by default. This should be the equivalent of configuring the standard Gradle test logging with the below settings.

testLogging {
    exceptionFormat "full"
    showExceptions true
    showCauses false
    showStackTraces true
}

Allow testlogger to be configured independently for each task

Test logger should be configurable for each task (of type Test of course) independently. So if a project has multiple test tasks, they should be able define different values. A typical example:

testlogger {
    theme 'standard' // global
}

test {
    maxParallelForks = 8
    testlogger {
        theme 'standard-parallel' // use a parallel theme
    }
}

task functionalTest(type: Test) {
    maxParallelForks = 1 // no parallelisation
    testlogger {
        theme 'mocha'
        slowThreshold 10000 // as my functional tests are normally slow
    } 
    
    include 'com/adarshr/gradle/testlogger/functional/**'
}

Currently testlogger can only be configured globally.

Print list of tests before execution

Not sure if this is possible with JUnit, but I'd like to see the list of tests before they're run. I have some long test suites and knowing that the tests I want to execute will be executed is very much useful to me.

Consider adding option to show failed only tests in output.

Would be great to have an option to show only failed tests in CI(Jenkins) build output. We have pretty big amount of tests and Jenkins output overflows several times, while at the same time in case if build failed on CI passed tests are not necessary things there. Smth. like

testLogger {
    showOnlyFailedInPlainOutputMode true
}

This will work only for --console=plain option enabled.
Also maybe legit if this flag is enabled by default for --console=plain

Summary doesn't fully overwrite existing lines

If there is a line on the console that's longer than what the summary would be, it isn't fully overwritten.

screen shot 2017-11-06 at 12 13 04

In the above case, the summary should've read

FAILURE: Executed 22 tests in 8.8s (2 failed, 1 skipped)

Post suite summaries

After completing a suite, a summary of some kind would be nice:

testlogger {
    showSummary true|false
}

The color in the current output is extremely useful for finding exactly which test failed while scrolling through, the summary could be an at-a-glance way to know what failed. I'm thinking the following pieces of information would be useful:

  • Task status: SUCCESSFUL/FAILED/ERROR
  • Number of tests
  • Number passed
  • Number skipped
  • Number failed
  • Number errored
  • List of Package/Class/Method of failed and errored tests

I've been putting the following in our build.gradle files, but it would be nice not to have to repeat it everywhere:

afterSuite { desc, result ->
       if (!desc.parent) { // will match the outermost suite
           def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
           def startItem = '|  ', endItem = '  |'
           def repeatLength = startItem.length() + output.length() + endItem.length()
           println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
       }
   }

Update documentation

Update documentation with usage instructions and GIFs for different platforms.

Testsuite fatal error output not shown

With a config like this:

testlogger {
	showStandardStreams true
	
	showPassedStandardStreams false
	showSkippedStandardStreams false
	showFailedStandardStreams true
}

if the test suite run itself fails - i.e. not 'a test does not pass' but the test execution failing due to something else e.g. an @Sql setup script with an error in it - gradle fails and stderr says:

> Task :test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.

but there's no indication as to what the problem was. If I run again with --info I can see that the stdout explains the problem in detail, but that disables the above testlogger filters.

Could testlogger notice the suite failure and show the output please?

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.