Saturday, May 12, 2012

Generate TestNG-xslt report using Maven

Earlier I had covered in my blog on how to generate a TestNG-xslt report for your TestNG test-case execution using Ant. Following is the link to it:
http://blog.varunin.com/2010/05/generating-selenium-reports-using.html

As many of the recent projects are now using maven as their build tool ,test-cases are also required to integrate itself to the existing build. In this blog I will mention about how to generate a TestNG-xslt report for your TestNG test-case execution using Maven.
Following is the "pom.xml" file for executing TestNG test-cases and to generate a "TestNG-xslt" report for the same:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.testng.app</groupId>
  <artifactId>my-testng</artifactId>
  <packaging>jar</packaging>
  <name>my-testng</name>
  <version>1.0-SNAPSHOT</version>
  <url>http://maven.apache.org</url>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <encoding>iso-8859-1</encoding>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <reporting>
    <plugins>
    <!-- TestNG-xslt related configuration. -->
      <plugin>
        <groupId>org.testng.xslt</groupId>
        <artifactId>testng-xslt-plugin</artifactId>
        <version>1.1</version>
        <configuration>
          <!-- Output directory for the report -->
          <outputDir>${project.basedir}/target/testng-xslt-report</outputDir>
          <sortTestCaseLinks>true</sortTestCaseLinks>
          <testDetailsFilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testDetailsFilter>
          <showRuntimeTotals>true</showRuntimeTotals>
        </configuration>
      </plugin>
    </plugins>
  </reporting>

  <dependencies>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.1.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <pluginRepositories>
    <pluginRepository>
      <id>testng-xslt-plugin</id>
      <url>http://www.cosminaru.ro/maven/</url>
    </pluginRepository>
  </pluginRepositories>

</project>
Run the following command to run your test cases and generate the TestNG-xslt report.

mvn clean test site

To know more about the TestNG-xslt configuration parameters please refer to my earlier blog post:
http://blog.varunin.com/2010/05/generating-selenium-reports-using.html