Verbose TestNG report with Maven Surefire

Verbose TestNG report with Maven Surefire

Using TestNG console output can be very inconvenient if you have lots of test cases. The better solution is to create an HTML report containing detailed information about testing progress. You can use the Maven Surefire plugin for this. Surefire report is a part of the project maven website, so at first we need to find out what is it.

Maven  site

Since you use Java to write Selenium tests you are free to use Maven tool to run lifecycle phases. The “Site” phase includes creating a project’s website with whole information about it (e.g. dependencies, documentation, plugins, etc.). To  create your project’s website just run this command

mvn site

or run Maven phase in Intellij Idea interface

After the task will complete go to the target/site directory in the project base directory. Open index.html file in any browser you have.

Maven Surefire Report

To add Surefire report to the project website just add reporting section to the pom.xml file

<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>com.mysite</groupId>
  <artifactId>seleniumtests</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
........
<reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.20</version>
      </plugin>
    </plugins>
  </reporting>
</project>

After that, run Maven site phase again and refresh the project website main page. You should see new “Project Reports” section.

There you can find detailed information about the last testing attempt.

Author: vlad