Showing posts with label Report. Show all posts
Showing posts with label Report. Show all posts

Wednesday, September 04, 2013

Ant task for ReportNG report

This is same like testng report, and also it uses "testng" task to execute the tests, just the difference is we need to specify a listener to it in its "listener" attribute.
This task also executes all the tests with group "alltests" and places the report in the "reprots.reportng" directory specified in the ant property.
 

 
 
  
   
   
   
  
 
Here in my example i have used custom listener to customize the report in com.myorg.core.util.GenericReportNGListener class, you can use the default listener by setting useDefaultListeners="true" as attribute of above testng task. You can give title to your ReportNG report in the ant task like here i gave "All Page Tests". This title will be shown in the report.

A ReportNG report looks like as below:


 The overview of the report looks something like this:



Thursday, June 20, 2013

Ant task for generating XSLT report

Once you are executed the test by TestNG or TestNG with Group, you can invoke the following ant target to generate xslt report.
 

 
 
  
   
   
  
 
Note: To work this above code you should have the following 2 jars in your class path:
SaxonLiaison.jar and saxon-8.7.jar 
In my example i have used a custom style which is specified in the "xslt_style/testng-results.xsl" file. After executing this target you will find your xslt report in "index.html" file which is in the "reports.xslt" directory specified in the ant property.

The report generated by testng with xslt looks something like the below image:


Thursday, February 14, 2013

Ant task for generating Cobertura report

The post describes how to use coburtura in the ant task. First of all you must tell ant about the Cobertura Ant tasks using a taskdef statement. The best practice is to place this before any target statements.
 
 
  
  
   
   
   
   
   
  
 

 
 
We must specify for Cobertura which class files to instrument by passing in ant filesets. You need to specify the directory location in "todir" to place the instrumented classes. You can exclude classes by using "excludeclasses" tag or using "ignore". Specify the name of the coverage data file to use in the "datafile" attribute. The default file is "cobertura.ser".

Cobertura-Instrument Task:
 
 
  
   
   
  
 

Running tests(Here i used TestNG to run tests):
The following components are the most important to get cobertura code coverage to work with testng.
This is a static variable that contains the location of the datafile. If the datafile moves, this lets the JVM know that the datafile has moved and is not in the current(or present) working directory.


Adding the instrumented classes before the actual classes guarantees that cobertura source code gets used first. This is required because we want to use the cobertura instrumented code instead of the regular compiled code, however we keep both versions just in case there's an issue with instrumentation.

Creating a reference id that contains just the cobertura.jar is important to guarantee that there is no NoClassDefFound exception with cobertura. When executing test units, the only dependency cobertura requires is the cobertura.jar file. All the other files are necessary for instrumentation, reporting and merging of tasks.
  
 
  
  
  
  
  
  
  
 

Cobertura-Report Task:
For generating cobertura report we need to use "cobertura-report" tag with the source file director specified in "srcdir" and destination report directory in "destdir" attribute.
 
 
 
  
   
   
   
   
   
   
   
  

  
  
 

The report generated by the cobertura looks like as the below snapshot:


Sunday, March 25, 2012

Ant task/script for generating TestNg report

Here is an example explaining an ant task for generating TestNG report after execution of classes defined in TestNG xml file.
  1. <property name="src.dir" value="src" />
  2. <property name="lib.dir" value="lib" />
  3. <property name="log.dir" value="logs" />
  4. <property name="build.loc" value="build" />
  5. <property name="classes.dir" value="${build.loc}/classes" />
  6. <property name="reports.dir" value="${build.loc}/reports" />
  7. <property name="testNG.report" value="${reports.dir}/TestNG" />
  8. <property name="suite.dir" value="suite" />
  9. <!-- Class-Path -->
  10. <path id="classpath">
  11.     <pathelement location="${classes.dir}"/>
  12.     <fileset dir="${lib.dir}" includes="*.jar"/>
  13. </path>
  14. <!-- Delete directories that are not needed -->
  15. <target name="delete-dir" >
  16.         <delete dir="${build.loc}"/>
  17.         <echo> /* Deleted existing Compiled Directory Classes */ </echo>
  18. </target>
  19. <!-- Create Directories -->
  20. <target name="create-source-dir" depends="delete-dir">
  21.     <mkdir dir="${classes.dir}"/>
  22.     <mkdir dir="${testNG.report}"/>
  23.     <echo> /* Created Directories */ </echo>
  24. </target>
  25. <!-- Compiling Tests -->
  26. <target name="compile-classes" depends="create-source-dir">
  27.     <javac destdir="${classes.dir}" includeantruntime="false" debug="true" srcdir="${src.dir}">
  28.         <classpath refid="classpath"/>
  29.     </javac>
  30.     <echo> /* Compiled Directory Classes */ </echo>
  31. </target>
  32. <!-- Running Tests and TestNG report generation -->
  33. <target name="testNGreport" depends="compile-classes">
  34.     <taskdef resource="testngtasks" classpathref="classpath"/>
  35.     <testng classpathref="classpath" outputDir="${testNG.report}" haltOnfailure="true">
  36.           <xmlfileset dir="." includes="${suite.dir}/testng.xml" />
  37.     </testng>
  38.     <echo> /* Run Directory Classes */ </echo>
  39. </target>
By the above target 'testNGreport' you can load TestNG task in ant and execute you selenium tests. It is just that ant would access your testng.xml file to execute tests. This is same as how you be executing tests from with eclipse using TestNG - Eclipse plugin. 
Below is the testNG file that is used in the above build file.
//TestNG.xml
  1. <suite name="Suite1" verbose="1" >
  2.   <test name="Regression1">
  3.     <classes>
  4.       <class name="test.sample.ExampleTest1"/>
  5.       <class name="test.sample.ExampleTest2"/>
  6.     </classes>
  7.   </test>
  8. </suite>

Monday, March 19, 2012

Ant task/script for generating JUnit report

Here is an example explaining an ant task for running compiled classes and generating JUnit report after execution of classes.
  1. <target name="run-classes" depends="compile-classes">
  2.     <!-- Define the Ant tasks for running classes -->
  3.     <junit fork="yes" printsummary="no" haltonfailure="no">    
  4.         <batchtest fork="yes" todir="${build.loc}/reports" >
  5.           <fileset dir="${classes.dir}">
  6.             <include name="**/.class" />
  7.           </fileset>
  8.         </batchtest>
  9.         <formatter type="xml" />
  10.         <classpath refid="classpath" />
  11.     </junit>
  12.    
  13.     <!-- Ant task for generating reports -->
  14.     <junitreport todir="${build.loc}/reports">
  15.         <fileset dir="${build.loc}/reports">
  16.             <include name="TEST-*.xml"/>
  17.         </fileset>
  18.         <report todir="${build.loc}/reports"/>
  19.     </junitreport>     
  20.     <echo> Genereated JUnit Reports </echo>
  21. </target>

In the above ant target there are 2 sub-tasks i.e junit and junitreport.The junit task is for running test classes and junitreport is for generating JUnit report.

Explanation:
fork
     if true, it 'll run the tests in separate virtual machine.
printsummary:
     if yes, at the end of the test, a one-line summary will be printed.
haltonfailure:
     if yes, the build process will be stopped if the test fails.
The batchtest defines a number of tests based on pattern matching.
In this case formatter type is xml so an XML result will be output to result xml file

        The batchtest task of junit task 'll run all the tests classes that are in ${classes.dir} directory and produce xml files in the ${build.loc}/reports directory then the junitreport task take all the xml files that are starting with 'TEST-' and 'll generate report in the same directory.