Difference between revisions of "NUnit support tools"

From Catglobe Wiki
Jump to: navigation, search
(NUnit HTML report generator)
Line 18: Line 18:
  
 
== NUnit HTML report generator ==
 
== NUnit HTML report generator ==
 +
There are time when we need to store the result after one unit test running for later reference. NUnit can export the run result into an XML file, however it is not user friendly. In this section, I will introduce a free tools for generate HTML report from such XML file.
  
 +
The tool is NUnit2Report, its homepage is http://nunit2report.sourceforge.net/
 +
 +
The tool is in fact a NAnt task, so we must have NAnt installed. Homepage of NAnt: http://nant.sourceforge.net/
 +
 +
'''Installation:'''
 +
*Download the latest version of NAnt
 +
*Unzip it to a folder name %NANTHOME%
 +
*''Make sure %NANTHOME%\bin folder is in your PATH environment variable''
 +
*Download the later version of NUnit2Report
 +
*Unzip the file to a folder name %NUNITREPORTHOME%
 +
*''Copy all file if %NUNITREPORTHOME%\bin to %NANTHOME%\bin''
 +
 +
'''Usage:'''
 +
*Export test running result to xml file. This can be done in 2 ways:
 +
#With NUnit-gui, after running the test, go to menu ''Tools -> Save Results as XML''
 +
#With Nunit-console, by default a file ''TestResult.xml'' will be generated in working directory. Otherwise, you can set the output file by putting /output parameter
 +
*Assume we have a result file as %RESULT%\TestResult.xml, create a text file in folder %RESULT% with extension '''.build'''
 +
*Copy following content to the file:
 +
 +
<source lang=xml>
 +
<?xml version="1.0" encoding="ISO-8859-1" ?>
 +
<project name="NUnitReport" default="nunitreport" basedir=".">
 +
<tstamp property="build.date" pattern="dd-MM-yyyy" verbose="true"/>
 +
<sysinfo/>
 +
<target name="nunitreport">
 +
<nunit2report out="DomainTester.html">
 +
<fileset>
 +
<include name="TestResult.xml" />
 +
</fileset>
 +
</nunit2report>
 +
</target>
 +
</project>
 +
</source>
 +
 +
In which:
 +
#'''DomainTester.html''': HTML output file name
 +
#'''TestResult.xml''': NUnit test result file name
 +
 +
*Now, it's ready for generating the report. Open command line console (cmd.exe), move to folder %RESULT%, type ''nant'' (make sure NAnt's bin folder is in your PATH environment or you would get an invalid path error message)
 +
*A DomainTester.html is generated in folder %RESULT%. Open it and you will get something like this:
 +
[[Image:NUnitReport.png|thumb|center|600px|HTML report for NUnit]]
 +
 +
Note that, the result is alphabetically sorted by TextFixture's name, this is not the same as in NUnit-Gui which groups TestFixtures by its namespace. If this causes problem identifying the correct method on NUnit-Gui by referencing to the HTML report (you might want to re-run a failed test method after fixing something) then the following tool can give some help.
 +
 +
Usage:
 +
*Copy ''\\catproc\Share\CatGlobe Teams\R & D\Personal\Chinh\RefineNUnitTestResult.exe'' to the same folder as ''TestResult.xml''
 +
*Run the executable. <u>Note: the programe requires no argument and will update the TestResult.xml</u>.
 +
*Now, run NAnt as above and you will get some thing as below:
 +
[[Image:NUnitReport-Refined.png|thumb|center|600px|TestFixtures sorted using full TestFixture name (including namespace)]]
  
 
== One click restore database ==
 
== One click restore database ==

Revision as of 06:33, 22 December 2008

Introduction

NUnit is one of the most popular tool for unit testing in .NET. And the most important thing is that it is used inside CatGlobe and now we are approaching Test-Driven-Development, this means that developers/testers must involve in using NUnit more and more.

In this page, I will introduce some small supporting tools that can add some value working with NUnit.

NCover and NCoverExplorer

NUnit does not provide a mean for checking code coverage, we have to use some third-party tools. The easiest and free tool is NCover. However, NCover just supports for exporting the code coverage result into xml file. Luckily we also have another free tool for exploring the coverage result - NCoverExplorer

Download the 2 tools from:

NCover

NCoverExplorer

NUnit HTML report generator

There are time when we need to store the result after one unit test running for later reference. NUnit can export the run result into an XML file, however it is not user friendly. In this section, I will introduce a free tools for generate HTML report from such XML file.

The tool is NUnit2Report, its homepage is http://nunit2report.sourceforge.net/

The tool is in fact a NAnt task, so we must have NAnt installed. Homepage of NAnt: http://nant.sourceforge.net/

Installation:

  • Download the latest version of NAnt
  • Unzip it to a folder name %NANTHOME%
  • Make sure %NANTHOME%\bin folder is in your PATH environment variable
  • Download the later version of NUnit2Report
  • Unzip the file to a folder name %NUNITREPORTHOME%
  • Copy all file if %NUNITREPORTHOME%\bin to %NANTHOME%\bin

Usage:

  • Export test running result to xml file. This can be done in 2 ways:
  1. With NUnit-gui, after running the test, go to menu Tools -> Save Results as XML
  2. With Nunit-console, by default a file TestResult.xml will be generated in working directory. Otherwise, you can set the output file by putting /output parameter
  • Assume we have a result file as %RESULT%\TestResult.xml, create a text file in folder %RESULT% with extension .build
  • Copy following content to the file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<project name="NUnitReport" default="nunitreport" basedir=".">
	<tstamp property="build.date" pattern="dd-MM-yyyy" verbose="true"/>
	<sysinfo/>
	<target name="nunitreport">
		<nunit2report out="DomainTester.html">
			<fileset>
				<include name="TestResult.xml" />
			</fileset>
		</nunit2report>
	</target>
</project>

In which:

  1. DomainTester.html: HTML output file name
  2. TestResult.xml: NUnit test result file name
  • Now, it's ready for generating the report. Open command line console (cmd.exe), move to folder %RESULT%, type nant (make sure NAnt's bin folder is in your PATH environment or you would get an invalid path error message)
  • A DomainTester.html is generated in folder %RESULT%. Open it and you will get something like this:
HTML report for NUnit

Note that, the result is alphabetically sorted by TextFixture's name, this is not the same as in NUnit-Gui which groups TestFixtures by its namespace. If this causes problem identifying the correct method on NUnit-Gui by referencing to the HTML report (you might want to re-run a failed test method after fixing something) then the following tool can give some help.

Usage:

  • Copy \\catproc\Share\CatGlobe Teams\R & D\Personal\Chinh\RefineNUnitTestResult.exe to the same folder as TestResult.xml
  • Run the executable. Note: the programe requires no argument and will update the TestResult.xml.
  • Now, run NAnt as above and you will get some thing as below:
TestFixtures sorted using full TestFixture name (including namespace)

One click restore database

One click attach NUnit