Giter VIP home page Giter VIP logo

spock-reports's Introduction

Spock Reports Extension

by Renato Athaydes

Check out the latest news about this project!

Actions Status Maven Central

What it is

This project is a global extension for Spock to create test (or, in Spock terms, Specifications) reports.

By default, the report creator generates a HTML report for each Specification, as well as a summary of all Specifications that have been run (index.html).

If you prefer to have your own template to generate reports from, you can use the TemplateReportCreator. This allows you to generate reports in any text format. See the "Using template reports" section below.

Support for Geb tests: if you use Geb for web testing, check out the geb-spock-reports extension which adds screenshots to Spock reports.

Where to find demo reports

I am using CodePen to design the HTML feature report, which contains detailed information about each Specification run by Spock, including the examples given (Where block) and their results, if any, and the summary report, which summarizes the results of all Specification runs. Click on the links to see the reports used for testing.

If you don't like the styles, you can use your own css stylesheets (see the customization section below). I welcome feedback on how to improve the report looks!

How to use it

To enable this Spock extension, you only need to declare a dependency to it (if using Maven, Ivy, Gradle etc) or, just add the jar to the project's classpath.

Spock-reports is available on Maven Central.

Version compatibility:

Java Groovy Spock spock-reports
8+ 4.0+ 2.3-groovy-4.0 2.5.1-groovy-4.0
8+ 3.0+ 2.3-groovy-3.0 2.5.1-groovy-3.0
8+ 2.5+ 2.0-groovy-2.5 2.0-groovy-2.5
7, 8 2.4+ 1.3+ 1.8.0

If you are using Maven

Add spock-reports to your <dependencies>:

<dependency>
  <groupId>com.athaydes</groupId>
  <artifactId>spock-reports</artifactId>
  <version>$spockReportsVersion</version>
  <scope>test</scope>
  <!-- this avoids affecting your version of Groovy/Spock -->
  <exclusions>
    <exclusion>
      <groupId>*</groupId>
      <artifactId>*</artifactId>
    </exclusion>
  </exclusions>
</dependency>

<!-- // if you don't already have slf4j-api and an implementation of it in the classpath, add this! -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.36</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.36</version>
  <scope>test</scope>
</dependency>

If you are using Gradle

repositories {
    mavenCentral()
}

test {
    useJUnitPlatform()
}

dependencies {
    // you can use testRuntimeClasspath if you don't want to use spock-report-specific features in your Specs
    testImplementation( "com.athaydes:spock-reports:$spockReportsVersion" ) {
        transitive = false // this avoids affecting your version of Groovy/Spock
    }
    // if you don't already have slf4j-api and an implementation of it in the classpath, add this!
    testImplementation 'org.slf4j:slf4j-api:1.7.36'
    testRuntimeClasspath 'org.slf4j:slf4j-simple:1.7.36'
}

If you prefer, you can just download the jar directly from Maven Central.

The only dependencies this project has are Groovy (only the groovy, groovy-templates, groovy-xml and groovy-json modules are required) and Spock, of course.

Adding information to reports programmatically

If you want to add information to your Spock-reports programmatically, since version 1.4.0, you can use the following Specification class' extension methods which are added by Spock Reports:

  • void reportHeader( arg ) - dynamically insert data into the top of the Specification report.
  • void reportInfo( arg ) - add data to the feature's section.

These methods are added as Groovy extensions, so your IDE should be able to show them in auto-completion!

For example, you could do something like this within your Specification:

def setupSpec() {
    reportHeader "<h2>Browser: ${driver.browser.name}</h2>"
}

def "My feature"() {
    expect:
    reportInfo "Some information I want to show in the report"
}

Customizing spock-reports logging

spock-reports uses the slf4j-api for logging, so you can get logging information to investigate any issues you may face with your Spock tests.

If your application does not have a slf4j implementation framework in the classpath, you may get this warning when running your tests:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

To get rid of the warning, add a dependency on a logging framework that implements the slf4j-api.

For example, to use slf4j-simple, add this line to your Gradle dependencies (or the equivalent XML in your Maven pom):

testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'

To configure the logging framework itself, please check the documentation of the framework you decide to use. If you're using slf4j-simple, check this.

Most logging messages emitted by spock-reports use the DEBUG level, except when errors happen, in which case the WARN level is used.

The base spock-reports's logger name is com.athaydes.spockframework.report.

Customizing the reports

Spock-reports can be configured via the Spock config file, a dedicated properties file or system properties.

All properties listed below are supported either way.

Using SpockConfig.groovy

supported since version 1.5.0

All properties for spock-reports should be added in the spockReports block. To set properties, use the following syntax:

spockReports {
    set 'com.athaydes.spockframework.report.showCodeBlocks': true
    set 'com.athaydes.spockframework.report.outputDir': 'target/spock-reports'
}

Alternatively:

spockReports {
    // set all properties at once
    set( [ 'com.athaydes.spockframework.report.showCodeBlocks': true,
           'com.athaydes.spockframework.report.outputDir': 'target/spock-reports' ] )
}

Using a properties file

If you prefer to use a properties file, the file should be located at the following location (relative to the classpath):

META-INF/services/com.athaydes.spockframework.report.IReportCreator.properties

If you use Grails, the above location will not work... the correct location depends on the Grails version you're using. See the following blog posts by @rdmueller for instructions:

Using system properties

If you use Gradle and prefer system properties, they should be configured on the test task, e.g.:

task('functionalTest', type: Test) {
  systemProperty 'com.athaydes.spockframework.report.outputDir', 'build/reports/spock'
}

If you use Maven and prefer system properties, they should be configured as systemPropertyVariables in the configuration section of the failsafe and surefire plugins.

Default properties' values

# Name of the implementation class(es) of report creator(s) to enable (separate multiple entries with commas)
# Currently supported classes are:
#   1. com.athaydes.spockframework.report.internal.HtmlReportCreator
#   2. com.athaydes.spockframework.report.template.TemplateReportCreator
com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.internal.HtmlReportCreator

# Set properties of the report creator
# For the HtmlReportCreator, the only properties available are
# (the location of the css files is relative to the classpath):
com.athaydes.spockframework.report.internal.HtmlReportCreator.featureReportCss=spock-feature-report.css
com.athaydes.spockframework.report.internal.HtmlReportCreator.summaryReportCss=spock-summary-report.css
com.athaydes.spockframework.report.internal.HtmlReportCreator.printThrowableStackTrace=false
com.athaydes.spockframework.report.internal.HtmlReportCreator.inlineCss=true
com.athaydes.spockframework.report.internal.HtmlReportCreator.enabled=true
# options are: "class_name_and_title", "class_name", "title"
com.athaydes.spockframework.report.internal.HtmlReportCreator.specSummaryNameOption=class_name_and_title

# exclude Specs Table of Contents
com.athaydes.spockframework.report.internal.HtmlReportCreator.excludeToc=false

# Output directory (where the spock reports will be created) - relative to working directory
com.athaydes.spockframework.report.outputDir=build/spock-reports

# Output directory where to store the aggregated JSON report (used to support parallel builds)
com.athaydes.spockframework.report.aggregatedJsonReportDir=

# If set to true, hides blocks which do not have any description
com.athaydes.spockframework.report.hideEmptyBlocks=false

# Set the name of the project under test so it can be displayed in the report
com.athaydes.spockframework.report.projectName=

# Set the version of the project under test so it can be displayed in the report
com.athaydes.spockframework.report.projectVersion=Unknown

# Show the source code for each block
com.athaydes.spockframework.report.showCodeBlocks=false

# Set the root location of the Spock test source code (only used if showCodeBlocks is 'true')
com.athaydes.spockframework.report.testSourceRoots=src/test/groovy

# Set properties specific to the TemplateReportCreator
com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile=/templateReportCreator/spec-template.md
com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension=md
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile=/templateReportCreator/summary-template.md
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName=summary.md
com.athaydes.spockframework.report.template.TemplateReportCreator.enabled=true

Notes on outputDir

Be aware that the outputDir property is relative to the working directory.

For Maven projects which use the defaults, you might want to change the outputDir to target/spock-reports.

If your build system can cache build outputs (to, for example, skip unnecessary build steps when in/out do not change), register the outputDir as an output of the test task.

In Gradle, for example, this can be accomplished with the following declaration in your build.gradle file:

test {
    // set to the same value as 'com.athaydes.spockframework.report.outputDir'
    outputs.dir "$buildDir/spock-reports"
}

Customizing the report stylesheets

The CSS properties above can be set to either of the following kinds of values:

  • a classpath resource.
  • a URL (the value will be used to call Java's new URL(value).

If the value does not match a full URL starting with a protocol (eg. file:///usr/local/css/report.css), the value will be treated as an absolute path to a classpath resource.

For example, if you set the value of a CSS property to my-css/test-report.css, the resource /my-css/test-report.css will be looked up in all Jars and directories which are part of the classpath.

If you set the value to http://myhost.com/css/test-report.css, the resource at this URL will be read.

Disabling CSS inlining

By default, the CSS resource will be inlined in the HTML report.

If you set the inlineCss property to false, then the CSS resource will be copied to the outputDir directory, together with the HTML reports, with the following names:

  • feature-report.css (for the featureReportCss property).
  • summary-report.css (for the summaryReportCss property).

A link to the CSS resources with the above names will be added to the HTML file instead of inlining the CSS.

Using template reports

If you don't like the looks of the HTML report, or want your reports in a different text format, you can use the TemplateReportCreator to do that.

All you need to do to get started is provide a config file, or system properties, as explained above that set the IReportCreator to com.athaydes.spockframework.report.template.TemplateReportCreator:

com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.template.TemplateReportCreator

# Set properties of the report creator
com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile=/templateReportCreator/spec-template.md
com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension=md
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile=/templateReportCreator/summary-template.md
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName=summary.md

# Output directory (where the spock reports will be created) - relative to working directory
com.athaydes.spockframework.report.outputDir=build/spock-reports

# If set to true, hides blocks which do not have any description
com.athaydes.spockframework.report.hideEmptyBlocks=false

Just copy the above contents to a file at META-INF/services/com.athaydes.spockframework.report.IReportCreator.properties relative to the classpath (eg. in src/test/resources for Maven users) and spock-reports will create a MD (mark-down) report for your tests.

To provide your own template, change the location of the template files, the file extension you wish your reports to have, and the name for the summary report file, using the config file.

To get started with your own template, check the existing spec template file and the summary template.

You can see an example report created with the default spec template file here (this is actually used in the spock-reports tests).

How templates work

The template report creator uses Groovy's GStringTemplateEngine to create reports based on a template file.

This template mechanism is very simple to use, but also very powerful, as you can write any code you want in the template file.

There are two templates you should provide:

  • Spec report template: report for the run of a single Specification.
  • Summary template: contains a summary of all Specifications that have been run during a JVM lifetime.

Spec report template

Here's the most basic Spec template you could imagine, which simply outputs the name of the Specification that ran:

This is a Report for ${utils.getSpecClassName(data)}

As you can see, you can use ${variable} to run actual code whose result will be printed in the report. Another way to do this, is to use <% code %> blocks, as in the following example, which prints the name and result of all features in a Specification:

<%
    features.eachFeature { name, result, blocks, iterations, params ->
%>
Feature Name: $name
Result: $result
<%
    }
%>

NOTE: before version 1.2.6, eachFeature used to be called forEach. This had to be changed to avoid conflict with Java 8's method of the same name.

You probably noticed the use of some predefined variables in the template file code example. The available variables are:

  • data: an instance of SpecData containing the result of running a Specification.
  • reportCreator: the TemplateReportCreator instance.
  • fmt: an instance of StringFormatHelper. It provides methods such as String toTimeDuration( timeInMs ) and String escapeXml( String str ).
  • utils: the Utils class offers many useful methods like Map stats( SpecData data ), which returns statistics about the given Specification.
  • features: as shown above, is an Object whose eachFeature method allows you to iterate over all the features of a Specification. When inside the eachFeature closure, you can access directly all members of the current feature (an instance of FeatureInfo). So, for example, to get the Title annotation of a feature, you can call utils.specAnnotation( data, spock.lang.Title ).

As the default template file shows, you can get statistics for the Specification easily with this code snippet:

<% def stats = utils.stats( data ) %>
Report statistics: $stats

The variable stats is a Map containing the following keys:

failures, errors, skipped, totalRuns, totalFeatures, passed, successRate, time

So, you can use it in your template like this:

Features:           :  ${stats.totalFeatures}
Total number of runs:  ${stats.totalRuns}
Passed              :  ${stats.passed}
Number of failures..:  ${stats.failures}
Number of errors....:  ${stats.errors}
Number of ignored...:  ${stats.skipped}
Success rate........:  ${stats.successRate}
Total time (ms).....:  ${stats.time}

Created on ${new Date()} by ${System.properties['user.name']}

Summary template

The summary template has access to a single variable called data, which is a Map containing all the available data for all Specifications that were run.

For example, after running two Specifications named test.FirstSpec and test.SecondSpec, the data Map could look like this:

[
 'test.FirstSpec' : [ failures: 0, errors: 0, skipped: 2, totalRuns: 3, totalFeatures: 4, passed: 5, successRate: 0.1, time: 1000 ],
 'test.SecondSpec': [ failures: 0, errors: 1, skipped: 3, totalRuns: 4, totalFeatures: 6, passed: 6, successRate: 0.2, time: 2000 ],
]

You can then iterate over each Spec's data as follows:

<% data.each { name, map ->
      def s = map.stats
 %>| $name | ${s.totalRuns} | ${s.failures} | ${s.errors} | ${s.skipped} | ${s.successRate} | ${s.time} |
<% }
 %>

Check the default summary template for a full example.

Submitting pull requests

Please submit pull requests with bug fixes at any time!!

But if your Pull Request is about a new feature, please make sure to create an issue first so that we can all discuss whether it's a good idea and what's the best way to go about it.

Also, please notice that the master branch is supposed to contain only releases... the development branch is called dev, so all PRs should be submitted against dev, not master.

Thank you.

spock-reports's People

Contributors

bmsq avatar burkhufnagel avatar fenixcitizen avatar frankie0701 avatar grv87 avatar jaystgelais avatar jest avatar mfriedenhagen avatar rdmueller avatar renatoathaydes avatar simonwatts avatar slugger avatar szpak avatar thokari avatar tilmanginzel avatar tjuchniewicz 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spock-reports's Issues

Trying to use spock-reports with grails: Failed to load extension class

I get different results with different Grails and spock-reports versions (all running on windows)

Grails 2.2.4 with spock 0.7-groovy-2.0

  • spock-reports 1.2: runs fine, but I only get the index.html page. No pages for my Spec, but they are linked from the index.html
  • spock-reports 1.2.1/2: I get a "Failed to load extension class". The class loader can't find the SpockReportExtension

Grails 2.4.4 with spock 0.7-groovy-2.0

  • I can't find any reports with any 1.2.x version of spock-reports

Any idea?

can we write to the report from the specification code ?

Hi renato and all spock-reports lovers,

in order to generate even more documentation starting from spock specifications code, we'd like to write "dynamic strings" to the report; string literals next to BDD keywords are not enough in our case. Can we already do that, through which API or coding convention, please ? If not, do you have any recommendation for contributing to it ?
(such feature exist in tools like Cucumber or Gauge)

At first, people are typically thinking at expressions for documentation strings:
expect: "all following rules should be followed: ${resultFromSomeStaticCode()}"
(but we assume spock is not able to detect that it's documentation instead of code)

Thank you for any hints.

Nota bene: we're doing grails specifications, sometimes depending on @TestFor instrumentation, which is lately activated in the spec life cycle; for this reason, @Unroll + where: variables + #variable templating in doc string literals seems not working in certain cases.

Spock-Reports doesn't support Spock 1.0

It works with Spock v0.7-groovy-2.0, but it doesn't work with Spock v1.0-groovy-2.0.
The root cause is that the IGlobalExtension interface changed and it now has start() and stop() methods, which the v0.7 version did not have, and so an AbstractMethodError: null is thrown:

{code}
java.lang.AbstractMethodError: null
at org.spockframework.runtime.GlobalExtensionRegistry.startGlobalExtensions(GlobalExtensionRegistry.java:105)
at org.spockframework.runtime.RunContext.start(RunContext.java:63)
at org.spockframework.runtime.RunContext.get(RunContext.java:165)
at org.spockframework.runtime.Sputnik.runExtensionsIfNecessary(Sputnik.java:88)
at org.spockframework.runtime.Sputnik.run(Sputnik.java:61)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
{code}

Because of this, we cannot use the most recent features in Spock, since v0.7 is more than 2 years old.

Application Stack trace is not visible when a failure happens. Causing debug to be difficult

When my application fails with Spock Report listening, it replaces the application stack trace with all trace generated by spock and return a No Current Iteration Exception.

Example:
With Spock-reports enabled
I run my app and cause createUser method to fail.

Stack Trace:
initialization Error : No Current Iteration

With Spock-reports disabled
I run my app and cause createUser method to fail.

Stack Trace:
InvalidState Exception: unable to createUser

Hope this is clear.

Unroll with # variable in labels

Given:
a spec like this

@Unroll
def "should make bar equal to [#bar]  when foo equals [#foo]"() {
given: "having foo equal to [#foo]"
when: "I do sth"
then: "bar should be equal to [#bar]"
}

when:
spock-reports are exeuted

then:
it would be awesome to have the '#' prepended vars to be unrolled also in the labels inside the spec :)

Bug - "Return" hyper links on feature descriptions don't work

There is a "Return" hyperlink embedded in the description of each feature on the right hand side, which ( I assume ) should take you back to the "Summary" or "Features" section at the top of the page.

image

However, this has not been set up anywhere, so clicking on the link does not do anything.

Can this be fixed?

Logging does not work in certain classes

It was raised in ticked #63 that some classes don't seem to produce any logs whatsoever... for example, com.athaydes.spockframework.report.template.TemplateReportAggregator.

Feature Request: Report Templates

Finally, I can definitely create a template mechanism for spock-reports. Please make a feature request as well!

Hope this is the right place for such a request :-)

The spock-reports project is the best spock report I am aware of (besides the Spock V1.0 reports :-), but it would be even more flexible, if the core would collect the report data as model and feed it into a (HTML) template. This way, everybody could easily modify the template and add to it without breaking the reports for other users.

IMHO, one of the template engines already provided by Groovy would be a good start http://groovy.codehaus.org/Groovy+Templates .

Enhancement: Add "Failures due to Issue" column into Summary

It will be nice to see a number of failed tests, which are probably already known and thus has @issue annotation with e.g. link to issue in some bug tracker.

This could be a column "Failures due to issue" in a Summary table, which refers to a value containing a number of failed tests due to known issues (with @issue) ${failures}

Unroll shows wrong row index

When using @unroll with the following test, we'd expect indices 2 and 4 to be the failures... what we get is much different.

Test:

import spock.lang.Specification
import spock.lang.Unroll

class MaxSpec extends Specification {
    @Unroll
    def 'Get the max value of two numbers'() {
        expect: 'Should return the bigger number'
        Math.max(a, b) == c

        where: 'max(a,b) == c'
        a | b || c
        1 | 0 || 1
        2 | 3 || 3
        3 | 1 || 1
        4 | 2 || 4
        2 | 3 || 2
    }
}

Result:

screen shot 2016-05-26 at 4 17 10 pm

Link to Standard Out from Spock Reports

It would be really helpful if there could be an option to display the standard out for tests. When doing Agile end-of-iteration demos, it would be great to walk through the Spock Report and then inspect the standard out which could show that data was saved to a database, json returned from a service call, etc....

Can not generate reports

My project is build with Maven,

I have configured the properties file in META-INF/services/com.athaydes.spockframework.report.IReportCreator.properties relative to my class path under src/test/resources

I have taken same sample file content and placed in that properties file.
but it is not generating any reports

am I missing something?

Remove println statements in favour of logging framework

I'm attempting to use this extension in a command line application I'm working on. The println statements throughout are polluting my console window at runtime with no way to suppress. Would you be willing to replace those println statements with a logging framework (log4j, slf4j, etc.)? I'll do a pull request if you're willing to merge it, I just don't want to go to the trouble if you'll never accept a pull request that adds a dependency.

Alternatively, a config option or system property to suppress the println statements would be the next best option. A logging framework means other users can more easily control what output goes where.

Add support for issueUrlPrefix for @Issue

In @Issue we want to write only ID of the issue for example @Issue("SP-1234").

To support this we need to add configuration property issueUrlPrefix. Something similar to Spock implementation IssueExtension.

Or maybe there is a possibility to use IssueExtension in spock-reports?

Exception using spock-reports from gradle?

Yeah turned out to be some weird conflict somewhere. so the set of deps immediately below made it work. The issue related to the why I had the 'localGrovy()' and the exclude (see below) disappeared -- must have been some other problem. All good now -- Thanks!

dependencies {

// compile deps...

testCompile group: 'junit', name: 'junit', version: '4.10'   
//testCompile localGroovy()    
testCompile ("org.spockframework:spock-core:0.7-groovy-2.0+"){
    //exclude group: 'org.codehaus.groovy'
}    
testCompile 'com.athaydes:spock-reports:1.2'

}


Hi,

Love to try out your spock extension. I get this from gradle:

java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:84)
.....

Particulars about my environment:
gradle -version


Gradle 2.0

Build time: 2014-07-01 07:45:34 UTC
Build number: none
Revision: b6ead6fa452dfdadec484059191eb641d817226c

Groovy: 2.3.3
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_65 (Oracle Corporation 24.65-b04)
OS: Linux 3.15.10-201.fc20.x86_64 amd64

Bits of my gradle file:
..................
apply plugin: 'java'
apply plugin: 'groovy'

version = 0.8
group='com.promo'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'

repositories {
maven {
url pinAppsDepsRepo
}

jcenter()

}

dependencies {

//
//...blah blah removed compile depends
//

testCompile group: 'junit', name: 'junit', version: '4.10'

testCompile localGroovy()

testCompile ("org.spockframework:spock-core:0.7-groovy-2.0"){
    exclude group: 'org.codehaus.groovy'
}

testCompile 'com.athaydes:spock-reports:1.2'

}

I'd guess there is some up with the localGroovy() and the exclude and spock-reports 1.2.

Any suggestions?

I had to to the exclude to get spock working with groovy-2 because of ....

Enhancement: Add title of @Ignore and @Issue annotations into report just before related test

It would be nice to have titles of @ignore and @issue annotations in reports.

Reviewer will see the reason of a test failure or ignorance e.g. as a link to issue in bug tracker or some other resource.

For instance:

@Issue ("link_to_bug_tracker")
def "Failing test due to issue"() {
}

@Ignore ("Test isn't finished yet")
def "This could be a great test!"() {
}

Report should contain:

[some formatting related to @Issue]     link_to_bug_tracker
[test_header_formatting]                Failing test due to issue

[some formatting related to @Ignore]    Test isn't finished yet
[test_header_formatting]                This could be a great test!

adding spock-reports in maven project

Hi
I am new to maven.
I am trying to add spock-reports jar in my maven project.
I tried addind dependency and repository shown here.
Added jar file in classpath.

Still some how i am not able to reproduce spock report .
I am running maven test , Added scope as test in spock-reports dependency.

Character encoding

if the strings in your tests contain utf-8 characters (like german umlauts "äüö"), the generated html output will display them with the wrong encoding. This can easily be fixed by adding the utf-8 encoding to the html header:

Tests fail if using JDK 7 update 65 or JDK 8 update 11 due to VerifyError

This problem is due to the JDK temporarily disallowing some Groovy transformations because the Verifier was made more strict recently.

This can be easily fixed by avoiding the use of Groovy AST Transformations and other dynamic features.

This problem was apparently fixed for JDK 7 update 72, though.

Groovy should be a "provided" dependency

Users of Spock will already have a version of Groovy in the classpath... spock-reports should not enforce a particular version of Groovy in the classpath of users.

Currently, users can avoid this problem by declaring their dependency on spock-reports as follows:

testCompile "com.athaydes:spock-reports:1.2.4", {
        exclude module: 'groovy-all'
}

Feature Request: Artifact Links

So I'm using this reporter as part of a functional testing framework based on spock. The tests being executed in this context produce other artifacts -- namely logs & screenshots.

One of the features I've added in my fork is to be able to include links to these artifacts as part of the HtmlReportCreator. The screenshot shows a simple example of what it produces.

This is the only feature I haven't merged back into you; hoping you'll consider it so I don't have to maintain a fork (as the users of the project I'm working on have become dependent on this feature rather quickly). I've implemented it using some external libraries, which I know I'll have to drop, but I can do that if this is something you'll accept back on your end.

image

NullPointerException: Cannot get property 'className' on null object

Hey, I found another bug. If an initialization error occurs in a super class while executing a child specification, a NullPointerException is thrown in HtmlReportCreator and TemplateReportCreator in the following line. As a result the report is not created.

def specClassName = data.info.description.className

Example:

class SuperSpec extends Specification {
    @Shared def x = 1/0
}

class ChildSpec extends SuperSpec {
    def "feature"() {
        expect:
        true
    }
}

Proposed fix:
Replace all data.info.description.className occurrences with something like this:

def specClassName = data.info.description?.className
if (specClassName == null) {
    specClassName = data.info.subSpec?.description?.className
}

We could create a Utils.getSpecClassName(SpecData data) method, because the description is called in various different places. This fix seems to work and if you agree I can provide another pull request.

Enhancement: Apply different style for failed tests with @Issue

This could be really nice to have a possibility to single out failed tests with @issue from
failed tests not being annotated with @issue.

For this:

  1. Add new style for failed tests with @issue, e.g. feature-toc-failure-with-issue or feature-toc-issue and
    feature-description.failure-with-issue or feature-description.issue
  2. In default template apply some different color for new style, e.g. yellow #FFFF33

Reports are created but no summary (NullPointerException in Utils.groovy)

I can run tests and get reposrts for each test but not a summary.

my .properties-file is

com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.template.TemplateReportCreator

# Set properties of the report creator
com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile=/templates/spec-template.jira
com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension=jira
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile=/templates/summary-template.jira
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName=summary.jira

# Output directory (where the spock reports will be created) - relative to working directory
com.athaydes.spockframework.report.outputDir=build/spock-reports

# If set to true, hides blocks which do not have any description
com.athaydes.spockframework.report.hideEmptyBlocks=false

the paths are correct and no error is thrown or logged. I run test with or without single tests. Is a summary supposed to be always created. I do have a file aggregated_report.json created inside my spock-reports directory though. I use version 1.2.4.

Running Test from IntelliJ randomly throws No Current Iteration Exception

difficult to create recreation steps, as this happens randomly.
Thanks for this awesome framework.

Configuring com.athaydes.spockframework.report.SpockReportExtension
java.lang.RuntimeException: No current iteration!
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
at com.athaydes.spockframework.report.SpecInfoListener.error(SpockReportExtension.groovy:136)
at org.spockframework.runtime.MasterRunListener.error(MasterRunListener.java:64)
at org.spockframework.runtime.JUnitSupervisor.error(JUnitSupervisor.java:99)
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:332)
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:311)
at org.spockframework.runtime.BaseSpecRunner.runSpec(BaseSpecRunner.java:91)
at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:82)
at org.spockframework.runtime.Sputnik.run(Sputnik.java:63)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Skipped features count reporting the total feature method count

Total 15 feature methods in EditorSpecification (Stepwise).

Name                Features    Failed  Errors  Skipped Success rate    Time
EditorSpecification 6           0       1       15      83.33%          1 minutes, 7.294 second

The success rate I'm unsure about, also... looks like (6-1)/6 for this example? This may be by design, but are skipped methods not considered in the success rate?

Test fail on windows

ProblemBlockWriterSpec and TemplateReportCreatorSpec fail because of line endings.

Template Reports don't display the full stack trace

It appears that the default html report creator now has an option to print the full stack trace but that parameter doesn't appear to be used in the TemplateReport creator. Do you plan to add that functionality to the template reports as well?

Generate Spock Reports on Maven build failure

I would like to be able to have Spock Reports generate even if Maven reports build failure.

I believe there is a way to do this with Maven lifecycle phases but wanted to check if Spock Reports has it built-in or if it is a feature that can be added.

Live long and prosper!

Can't seem to get the child test html files to update

Running this the index.html file will update fine and show the correct stats for tests, however the child html class for each suite run will not update at all, show that they are passing regardless of whether or not they are. Let me know if this is some set-up issue on my end. I am using Maven and eclipse

Exception when spock fails to initialize spec

We have some data driven Spock Specifications which create database connections during startup and use the "@shared" annotation:
class ExampleSpec extends Specification { @Shared db = createDatabaseConnection() }

If an exception is thrown during initialization, SpecInfoListener.error() is triggered. Unfortunately, this produces a null pointer exception because SpecInfoListener.beforeSpec() is never called:

java.lang.NullPointerException: Cannot get property 'featureRuns' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:57)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:169)
at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44)
at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.callGroovyObjectGetProperty(GetEffectivePogoPropertySite.java:62)
at com.athaydes.spockframework.report.SpecInfoListener.currentRun(SpockReportExtension.groovy:170)
at com.athaydes.spockframework.report.SpecInfoListener.dummySpecIteration(SpockReportExtension.groovy:177)
at com.athaydes.spockframework.report.SpecInfoListener.error(SpockReportExtension.groovy:155)
at org.spockframework.runtime.MasterRunListener.error(MasterRunListener.java:64)
at org.spockframework.runtime.JUnitSupervisor.error(JUnitSupervisor.java:99)
....

The testing suite was going to fail anyway but the exception from Spock Reports is preventing the real exception from appearing in the logs.

My gut feeling is that this sort of error should be ignored by Spock Reports as the error isn't actually associated with a Spec.

Pull request to follow.

spock-reports index.html incomplete when running in parallel

Hello,
Thanks for your work on spock-reports. I'm seeing something strange that may very well be a configuration issue on my side, but I think this is the right place to ask.

I'm running spock-core:1.0-groovy-2.4 and spock-reports:1.2.5 via gradle, attempting to execute my specs in parallel. It seems that all of the per-spec spock-reports are being generated (ie. com.example.package.TestSpec.html), but the main index.html generated only contains one thread worth of results in summary. Is there a way to get the cumulative result of all threads put into spock-reports' index.html?

By comparison, the index.html contained in the reports generated by Spock itself seems to report comprehensive results across all threads.

Thanks,
Trey

Inline styles causing CSP violations

In both feature and summary reports all styles are inlined in the html code. In some cases this raises Content Security Policy violations which prevent the styles from being displayed. Setting com.athaydes.spockframework.report.internal.HtmlReportCreator.summaryReportCss / .featureReportCss doesn't help - the content of the provided css file simply gets inlined.

Would really appreciate to see this fixed (writing the issue instead of creating a pull request as per the readme file). Keep up the good work :)

Edit: This of course only happens when Content Security Policy is enabled on the target website, so it won't be noticed by everyone (especially while opening the files locally). It's still a pain when working in strict security enviroment though.

Encoding problem with TemplateReportCreator

I have encoding problems with German characters äöü. The Template is UTF-8-encoded. It features words like Übersicht (overview) which is correctly written to the report.

But the description from the Spock-tests (the one after when:, given: etc.) is encoded in ISO-8859-1 due to the fact that this is the default encoding on the system.

I would expect for description to conform to the output-encoding which seems to be UTF-8. Or how about a configuration option in the .properties-file.

ArrayIndexOutOfBoundsException at method featureNameFrom

I came across the following stacktrace, probably as a result of the fix for #70. I omitted most of it due to its length of 212 rows. The important part seems to be the call of the method com.athaydes.spockframework.report.internal.HtmlReportCreator.featureNameFrom

I still need to figure out why this occurred and hopefully can come up with a minimal specification producing this.

18:10:25.539 [Test worker] WARN  c.a.s.r.internal.HtmlReportCreator - Failed to create report for MySpec
java.lang.ArrayIndexOutOfBoundsException: 0
    at org.spockframework.runtime.extension.builtin.UnrollNameProvider.evaluateExpression(UnrollNameProvider.java:74) ~[spock-core-1.0-groovy-2.4.jar:na]
    at org.spockframework.runtime.extension.builtin.UnrollNameProvider.nameFor(UnrollNameProvider.java:53) ~[spock-core-1.0-groovy-2.4.jar:na]
    at org.spockframework.runtime.extension.builtin.UnrollNameProvider.getName(UnrollNameProvider.java:44) ~[spock-core-1.0-groovy-2.4.jar:na]
    at org.spockframework.runtime.extension.builtin.UnrollNameProvider$getName.call(Unknown Source) ~[na:na]
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[groovy-all-2.4.5.jar:2.4.5]
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[groovy-all-2.4.5.jar:2.4.5]
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-all-2.4.5.jar:2.4.5]
    at com.athaydes.spockframework.report.internal.HtmlReportCreator.featureNameFrom(HtmlReportCreator.groovy:212) ~[spock-reports-1.2.12.jar:1.2.12]
    [...]

Could not create custom template report - geting a runtime error "Template File does not exist: "

Hi Renato Athaydes,

Thank you for this Spock Reports Extension project, I really like it. I followed your instructions in your "ReadMe.md" for creating my own "spec-template.md" and "summary-template.md" to create reports using TemplateReportCreator.

These two .md files are in src/test/resources folder in my gradle project. I have configure gradle, geb, spock, spock-reports and others related dependencies for running the spock tests.

I have the following content in the META-INF/services/com.athaydes.spockframework.report.IReportCreator.properties file.

************************

com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.template.TemplateReportCreator

com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile=templateReportCreator/spec-template.md
com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension=md
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile=templateReportCreator/summary-template.md
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName=summary.md
com.athaydes.spockframework.report.outputDir=build/custom-spock-report

com.athaydes.spockframework.report.hideEmptyBlocks=false

************************

After running a test, it creates a empty folder in build named "custom-spock-report". I am getting an error messages that says:
"org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke WARNING: Unexpected error creating report: java.lang.RuntimeException: Template File does not exist: src/test/resources/spec-template.md".

I tried both "src/test/resources/spec-template.md" and "/src/test/resources/summary-template.md" but it could not the .md paths in both cases. It says file does not exist.

Can you please provide some help on this setup?

Thank you
Ram

Enhancement: Debug-Mode

Now that we can specify some properties as environment variables, some kind of loglevel=debug would be helpful, because spock-reports too often fails silent.

I the log-output, I would like to see

  • the classpath where the plugin looks for a properties file
  • in case of the template report generator, the absolute path + filename the generator expects the templates to be if it gets a file not found

Empty Markdown Files

Here is my properties-file:

# Name of the implementation class of the report creator
# Currently supported classes are:
#   1. com.athaydes.spockframework.report.internal.HtmlReportCreator
#   2. com.athaydes.spockframework.report.template.TemplateReportCreator
com.athaydes.spockframework.report.IReportCreator=com.athaydes.spockframework.report.template.TemplateReportCreator

# Set properties of the report creator
# For the HtmlReportCreator, the only properties available are
# (the location of the css files is relative to the classpath):
# com.athaydes.spockframework.report.internal.HtmlReportCreator.featureReportCss=spock-feature-report.css
# com.athaydes.spockframework.report.internal.HtmlReportCreator.summaryReportCss=spock-summary-report.css
# exclude Specs Table of Contents
# com.athaydes.spockframework.report.internal.HtmlReportCreator.excludeToc=false

# Output directory (where the spock reports will be created) - relative to working directory
com.athaydes.spockframework.report.outputDir=build/spock-reports-ad

# If set to true, hides blocks which do not have any description
com.athaydes.spockframework.report.hideEmptyBlocks=false

# Set properties of the report creator
com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile=/spockreporttemplate/spec-template.ad
com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension=ad
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile=/spockreporttemplate/summary-template.ad
com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName=summary.ad

In the specified folder (spock-reports-ad), only empty Markdown-Files are created. Did I do something wrong?

Edit: I checked out my "test-results" folder where details for the tests are saved as XML and they provide the following error message:

Unexpected error creatingreport
java.lang.NullPointerException

Use @Slf4j instead of @Log

Java logging is a massive pain to deal with, and SLF4J isn't. Considering that SLF4J can be configured to use Java logging if you so desire, it would be awesome if this utility supported it natively.

This is the line that I'm referring to: https://github.com/renatoathaydes/spock-reports/blob/master/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy#L21.

It causes the following output that has to be handled separately from all other logger types if you are not using Java logging (which fewer and fewer people are nowadays):

Nov 28, 2015 7:23:13 PM org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
INFO: Configuring com.athaydes.spockframework.report.SpockReportExtension
Nov 28, 2015 7:23:13 PM org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
INFO: SpockReports config loaded: [com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension:md, com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile:/templateReportCreator/spec-template.md, com.athaydes.spockframework.report.IReportCreator:com.athaydes.spockframework.report.internal.HtmlReportCreator, com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile:/templateReportCreator/summary-template.md, com.athaydes.spockframework.report.internal.HtmlReportCreator.summaryReportCss:spock-summary-report.css, com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName:summary.md, com.athaydes.spockframework.report.internal.HtmlReportCreator.featureReportCss:spock-feature-report.css, com.athaydes.spockframework.report.hideEmptyBlocks:false, com.athaydes.spockframework.report.outputDir:build/spock-reports]
Nov 28, 2015 7:23:13 PM org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
INFO: Loading settings for reportCreator of type com.athaydes.spockframework.report.internal.HtmlReportCreator

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.