12

As the title suggests, I'm trying to generate an HTML report of the JUnit results when my maven project executes. I was told to check out maven-surefire-report plugin by another person and it looks like it has what I'm wanting but I just can't seem to get the HTML file to generate. I'm looking to ONLY generate an HTML file that I could then put into an email for my bosses. I'm not really wanting to go down the road of having the results post to a site (at least not at the moment).

Here is what my pom section looks like for surefire (don't worry about missing tags. I'm copying and pasting the relevant sections, and trying not to paste company info, but know I have the proper opening / closing tags):

EDIT: Added full pom.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>myGroup</groupId>
    <artifactId>myArtifact</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>myName</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sourceforge.jtds/jtds -->
        <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.3.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>1.4.0.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.6.5</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>2.19.1</version>
            <type>maven-plugin</type>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <type>maven-plugin</type>
        </dependency>
    </dependencies>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.19.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <outputDirectory>${basedir}/target/site/surefire-report.html</outputDirectory>
                </configuration>
                <!--<configuration>-->
                    <!--<outputDirectory>C:\Users\ab66378\Desktop</outputDirectory>-->
                <!--</configuration>-->
            </plugin>
        </plugins>
    </reporting>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

As far as I know, and according to the guides and what not I've looked at, this is all I need. Just the pom dependency and the reporting plugin section but I'm still not seeing an HTML file generated.

I have a feeling the part that I'm missing is going to be very minimal but I just can't seem to find it.

user1818298
  • 509
  • 2
  • 8
  • 23
  • 1
    Do you have a target output file generated? Should be in there somewhere. If not, then it may be that you have not configured an output directory for the report. – robx Sep 27 '16 at 16:51
  • I did try messing around with output directories a little bit but I still couldn't find anything. I first attempted to add the output to just the desktop so I could see if it was working. Here is what it looked like: C:\Users\username\Desktop – user1818298 Sep 27 '16 at 16:56

4 Answers4

4

The default report should be located in ${basedir}/target/site/surefire-report.html

I believe you might need to include maven-surefire-plugin and junit in the plugins/dependencies respectively.

The surefire report plugin will automatically parse the files matching TEST-.xml in ${basedir}/target/surefire-reports but I believe you need the maven-surefire-plugin in order to generate the TEST-.xml files

Here is the documentation to the plugin. One way might be to run the build and see if the TEST-*.xml files are being generated.

http://maven.apache.org/surefire/maven-surefire-plugin/index.html

Dan King
  • 1,080
  • 1
  • 11
  • 28
  • Thanks a lot for the reply Dan. Here is a part that confuses me and I'm sure it's because I've not had a ton of experience setting things like this up before. Do I literally write ${basedir} or is that just a placeholder for a directory that I hard code myself. I don't have a ton of experience messing with paths and creating files and what not so it probably comes off as a newb question :) – user1818298 Sep 27 '16 at 17:36
  • 1
    ${baseDir} is director you pom resides in. You can type it in and maven will resolve it – Dan King Sep 27 '16 at 17:42
  • If you are still having issues posting your entire pom might help further in determining the issue – Dan King Sep 27 '16 at 17:53
  • OK so I added the maven-surefire-plugin dependency AND the plugin to the pom. I already had JUnit dependency at the top of the pom. When I execute my test it doesn't even look like the "site" folder is being created under "target". – user1818298 Sep 27 '16 at 18:10
  • I created a gist here https://gist.github.com/dwdking/eface84d904fc4dc2c51015b1d7e1958, it works for me if I do a mvn clean verify, the main change was I included the surefire report plugin within build/plugins and added the execution section. This executions could maybe be included in the reporting/plugins section of your surefire report plugin but I'm not positive – Dan King Sep 27 '16 at 18:58
  • Also, you might have to do something similar in order to get the site plugin to be triggered so you have a nice looking report – Dan King Sep 27 '16 at 19:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124344/discussion-between-dan-king-and-user1818298). – Dan King Sep 27 '16 at 19:01
  • Adding the execution section and then doing a clean / verify worked! I'm seeing the TEST-.xml files now. Now to try and turn it into HTML and send it via email :) – user1818298 Sep 27 '16 at 19:36
4

By default surfire plugin will create XML and txt files report in {base-dir}/target/surfire-reports. to generate HTML report you can use

mvn surefire-report:report-only

above command will use XML files and will create HTML report at {base-dir/target/site/surefire-report.html}

0

configure as below

<configuration>
<outputDirectory>${basedir}/target/newsite</outputDirectory>
</configuration>

using stand alone tool you can change the path like below

mvn surefire-report:report -DoutputDirectory=newpath
Arunakiran Nulu
  • 2,029
  • 1
  • 10
  • 16
0

Check if you have added your Runner-class inside Surefire plugin of the POM file:-

Check the attached screenshot