ReportNG is a plug-In for TestNG, using this we can generate HTML based report for our test.Here we learn how to setup ReportNG and how to build using ANT script.
Dowload ReportNG from here .
Step 2:
Extract the downloaded folder after that it looks like that
The
Step 3:
Write the Ant script as given below
<project name="TestNGTest" default="test" basedir=".">
<!-- Define <testng> task -->
<property name="testdir" location="test" />
<property name="libdir" location="lib" />
<property name="full-compile" value="true" />
<path id="classpath.test">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${testdir}\class" />
</path>
<taskdef resource="testngtasks" classpathref="classpath.test"/>
<target name="reportng" depends="testng">
<mkdir dir="${testdir}\ReportNgReport" />
<testng outputdir="${testdir}\ReportNgReport" classpathref="classpath.test" useDefaultListeners="false"
haltonfailure="false" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
<xmlfileset dir="${testdir}\javaapplication3" includes="NewTestNGSuite.xml"/>
<sysproperty key="org.uncommons.reportng.escape-output" value="false" />
<sysproperty key="org.uncommons.reportng.velocity-log" value="true"/>
<sysproperty key="org.uncommons.reportng.title" value="My Test Report"/>
<sysproperty key="org.uncommons.reportng.frames" value="true"/>
<sysproperty key="org.uncommons.reportng.failures-only" value="true"/>
<sysproperty key="org.uncommons.reportng.show-expected-exceptions" value="false"/>
</testng>
</target>
</project>
If we useDefaultListeners="false" then TestNg reporting files should not be created.
We need to set listner for HTML reporting
org.uncommons.reportng.HTMLReporter
We need to set listner for JUnit reporting (optional)
org.uncommons.reportng.JUnitXMLReporter
We can also set the various system property of the ReportNg like rendering screenshot for test failure,change the default title, logging,only failure test shown on the html report etc......
Solution:Download guice-3.0 from here ,extract the files and add guice-3.0.jar in our project lib.
Problem 2: Velocity Log not created
Solution : Actually if we set this <sysproperty key="org.uncommons.reportng.velocity-log" value="true"/>then log is created in system environment directory.So we need to set the working directory from TestNg.We can do this using workingdir attribute in <testng> tag like:
<testng workingdir="${basedir}/ReportNG" outputdir="${basedir}/ReportNG" classpathref="masterclasspath"
useDefaultListeners="false" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
- ReportNg SetUP
Dowload ReportNG from here .
Step 2:
Extract the downloaded folder after that it looks like that
The
reportng-1.1.4.jar
and velocity-dep-1.4.jar.jar
files must be
included into our project lib folder.Step 3:
Write the Ant script as given below
<project name="TestNGTest" default="test" basedir=".">
<!-- Define <testng> task -->
<property name="testdir" location="test" />
<property name="libdir" location="lib" />
<property name="full-compile" value="true" />
<path id="classpath.test">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${testdir}\class" />
</path>
<taskdef resource="testngtasks" classpathref="classpath.test"/>
<target name="reportng" depends="testng">
<mkdir dir="${testdir}\ReportNgReport" />
<testng outputdir="${testdir}\ReportNgReport" classpathref="classpath.test" useDefaultListeners="false"
haltonfailure="false" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
<xmlfileset dir="${testdir}\javaapplication3" includes="NewTestNGSuite.xml"/>
<sysproperty key="org.uncommons.reportng.escape-output" value="false" />
<sysproperty key="org.uncommons.reportng.velocity-log" value="true"/>
<sysproperty key="org.uncommons.reportng.title" value="My Test Report"/>
<sysproperty key="org.uncommons.reportng.frames" value="true"/>
<sysproperty key="org.uncommons.reportng.failures-only" value="true"/>
<sysproperty key="org.uncommons.reportng.show-expected-exceptions" value="false"/>
</testng>
</target>
</project>
If we useDefaultListeners="false" then TestNg reporting files should not be created.
We need to set listner for HTML reporting
org.uncommons.reportng.HTMLReporter
We need to set listner for JUnit reporting (optional)
org.uncommons.reportng.JUnitXMLReporter
We can also set the various system property of the ReportNg like rendering screenshot for test failure,change the default title, logging,only failure test shown on the html report etc......
- Some Error handling in ReportNG SetUP
Solution:Download guice-3.0 from here ,extract the files and add guice-3.0.jar in our project lib.
Problem 2: Velocity Log not created
Solution : Actually if we set this <sysproperty key="org.uncommons.reportng.velocity-log" value="true"/>then log is created in system environment directory.So we need to set the working directory from TestNg.We can do this using workingdir attribute in <testng> tag like:
<testng workingdir="${basedir}/ReportNG" outputdir="${basedir}/ReportNG" classpathref="masterclasspath"
useDefaultListeners="false" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
This comment has been removed by the author.
ReplyDeleteHi,
ReplyDeletethis is really good post, I really appreciate your work . We can generate ReportNg.html by configuring the TestNg.xml by following way:-
Add listener :-
then proceed with the XMl file.
java.lang.NoClassDefFoundError: com/google/inject/Module
> at java.lang.Class.getDeclaredMethods0(Native Method)
Please download google juice jar and add to your eclipse lib folder.
Then select Project properties ->testNG->Disable default listeners.
then you will get the ReportNG test results in the "test-output\html"
directory. Note: this is the default test results directory for
TestNG.
How to add system property in testng.xml file?
ReplyDeleteI would like to know how to achive the use of ReportNg System properties with testng.xml