spock-reports icon indicating copy to clipboard operation
spock-reports copied to clipboard

Combine reports in multi-module maven setup

Open alwyn opened this issue 8 years ago • 8 comments

Hi,

As an enhancement, could we configure spock-reports to generate a main report for a multi-module project?

It could either itself contain all the results or link to the results of sub-modules.

In my case the need arises because I am slowly migrating tests over to spock and they are strewn all over the show at the moment.

alwyn avatar Nov 04 '16 02:11 alwyn

Hi.

I've done something like this at work... But doing so requires an external tool, like a Maven/Gradle plugin because, as an extension of Spock, spock-reports is limited to one module (in my case, I wrote a Groovy script that gets called by GMaven from Maven).

spock-reports exposes lots of information about all Specifications it ran in a json file (easy to parse). Look at the spock-reports directory, there should be a file called aggregated_report.json. This is meant to provide the information for external tools to build a full report for a multi-module project.

It looks like this:

{
  "com.acme.MySpec": {
    "executedFeatures": [
      "Regex can replace value in String"
    ],
    "ignoredFeatures": [],
    "stats": {
      "failures": 0,
      "errors": 1,
      "skipped": 0,
      "totalRuns": 1,
      "successRate": 0.0,
      "time": 106
    }
  },
  "com.acme.OtherSpecification": {
    "executedFeatures": [
      "Some other feature"
    ],
    "ignoredFeatures": [],
    "stats": {
      "failures": 0,
      "errors": 1,
      "skipped": 0,
      "totalRuns": 1,
      "successRate": 0.0,
      "time": 135
    }
  },
  ...
}

Linking to the individual reports is very easy: just copy the name of the spec (eg. com.acme.MySpec in the example above) and add .html to it... the html reports are all located in the same directory as this json file, so an absolute link it trivial to create.

The general report for the module is called index.html, as you probably know.

renatoathaydes avatar Nov 04 '16 07:11 renatoathaydes

Hi @renatoathaydes do you think providing an option to prefix index.html with the module name is a good option?

sskjames avatar Oct 16 '17 08:10 sskjames

@sskjames something like that could work... I guess we just need to try and see what is needed.

renatoathaydes avatar Oct 16 '17 08:10 renatoathaydes

That's great. Thank you very much for creating this extension.

sskjames avatar Oct 16 '17 08:10 sskjames

@sskjames my pleasure :) it's good to know people appreciate it.

renatoathaydes avatar Oct 17 '17 08:10 renatoathaydes

Just a hint: for one multi-module project I just specified the output-dir to point to the parent project. Using the following in a profile of the project parent-pom, this stuff is only included when there are spock tests at all: You need to override the configuration for surefire and failsafe, the index page shows all tests.

    <profiles>
        <profile>
            <id>spock-reports</id>
            <activation>
                <file>
                    <exists>src/test/groovy</exists>
                </file>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.athaydes</groupId>
                    <artifactId>spock-reports</artifactId>
                    <version>1.5.0</version>
                    <scope>test</scope>
                    <!-- this avoids affecting your version of Groovy/Spock -->
                    <exclusions>
                        <exclusion>
                            <groupId>*</groupId>
                            <artifactId>*</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <configuration>
                                <systemProperties>
                                    <com.athaydes.spockframework.report.showCodeBlocks>true</com.athaydes.spockframework.report.showCodeBlocks>
                                    <com.athaydes.spockframework.report.outputDir>${user.dir}/target/spock-reports</com.athaydes.spockframework.report.outputDir>
                                </systemProperties>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <configuration>
                                <systemProperties>
                                    <com.athaydes.spockframework.report.outputDir>${user.dir}/target/spock-reports</com.athaydes.spockframework.report.outputDir>
                                </systemProperties>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>

mfriedenhagen avatar May 25 '18 16:05 mfriedenhagen

I would know the status of this work. I am facing the same issue that the application has a lot of plugins which are submodules. Spock report could not be generated into the target folder of those modules. How come?

ntung avatar Sep 17 '18 14:09 ntung

@ntung what do you mean? Multi-module Maven module reports should work... This issue is about combining multiple reports from sub-modules into one... Is that what you say is not working?

renatoathaydes avatar Sep 21 '18 16:09 renatoathaydes