index-1-1.jpg
  • Aurora Solutions

Using NUnit with CCNet

This is the fifth article of the series of Continuous Integration in .net using Cruise Control .net. In the last article we had covered the usage of NAnt with ccnet, in this article we move ahead and extend NAnt script to use NUnit and test the Test Cases in our application to ensure that the project is running successfully and then sharing the results of running the test cases with our feedback system both web dashboard and the email. NUnit is basically a testing api for .net and is use to write the test cases. Now lets move towards that how can we use NUnit and run our test cases. Will it not be easy that your system runs automatically and build(compile) our .net project and runs all the test cases and provide the detail feed back about the test cases that how many of them were succeed and how many were failed instead of running every test case one by one? Yes, off course it will be easy. You just get the feed back about your project specifically when you are building larger enterprise application, in which you want to ensure that every unit is working properly. Now this is far just about few lines and you will see that its not as much difficult to setup.


In our example of Trade Simulator, we have a test case which will be run in this example. In the last article we had used NAnt, we will use that to configure about the testing of our application.


Here is how to configure it.

<?xml version="1.0" encoding="utf-8"?>
<project name="Trade Simulator" default="TestCases">
<target name="build.Project">
   <delete dir="C:/results" />
   <exec program="C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe">
   <arg value="D:ReposcruisecontrolAurora_UIAurora_UI.sln" />
   <arg value="/t:Rebuild" />
   <arg value="/p:Configuration=Release" />
   </exec>
</target>
<target name="TestCases" depends="build.Project">
   <nunit2>
     <formatter type="Xml" usefile="true" extension=".xml" outputdir="C:/results" />
     <test>
      <assemblies>
       <includesfile name="UnitTestAssemblies.txt" />
      </assemblies>
       <categories>
        <include name="Unit" />
       </categories>
   </test>
   </nunit2>

</target>
</project>

The lines in "bold" are the new lines we made to our previous NAnt script, now see we have 2 targets one for building the solution and other for running the test. The test case target depends on the first target, because logically when the solution build is succeed than we have to run the test cases if there are some errors in the source code than we dont need to run the test cases as project is not fully build. Now lets discuss the target Test Cases.


In this first we had define the tag nunit 2 which is available in NAnt we just need to use it. Next we define the formatter type xml, which is used to store the result of the test cases, later we will use these files to see the results of the test cases. Next is the test tag which is the main tag under nunit2 tag. We provide the test cases assemblies in this tag which need to be tested. It is picking up the assemblies from a text file, we define the test assemblies with the path in this file to test it, currently we have only one assembly so this file contains:


D:ReposcruisecontrolAurora_UIServer.TestsbinReleaseServer.Tests.dll


Since our test project will be build in the above location. Next is categories since there can be multiple test cases in your project, you can categorize them in the following way.


You can define the category in this way about each test case.


So it will run all the unit test cases in the project provided in the assemblies.

<delete dir="C:/results" />

We wrote this because before building the project clean the previous test case results, so that it won't get mixed with the new ones.


Since now we had seen how the test cases are run in the cruise control.


Next step is off course the feedback. That what happened with the test cases they succeed of failed.


To include the results of the Test cases in the email we use the following lines in our publisher tag in ccnet config file.

<publishers>
<merge>
<files>
<file>C:results*-results.xml</file>
</files>
</merge>
<xmllogger />

It will include the results of test cases in the C:results folder which is generated by NUnit.


Now next step is how to configure your web dashboard to see the detailed results, it will be interested off course.


All you need is open your web dashboard in the web browser, go to administer dashboard in the menu, enter the password and than press enter, you will see the following screen.


Just click in NUnit Results a pop will come click on install to install the plugin now close the dashboard and restart your iis server so the changes take effect.


Here is the results of the build and test cases.


This is the NAnt timing, you can see the time taken by two targets.


This was the results we are waiting for, you can see details. Tested assemblies, test executed, passes and failures.

This picture shows the time taken by each test case.


So this was all about NUnit. In the next article i'll show you how can you automate the WIX installers in the cruise control.net


Previous articles link:

4. Using NAnt with CCNET

3. Using MSBuild with CCNET

2. Getting started with Cruise Contrl .NET

1. Introduction to Continuous Integration

Download Project & Configuration File

4 views0 comments

Recent Posts

See All

Automating WIX Installer using CCNET

This is the last article of the series Continuous Integration in .NET using Cruise Control.net. In the last article we had discussed that how we can use NUnit with ccnet to run our test cases. In this

Using MSBuild with CCNet

This is the third article of the series of Continuous Integration in .net, in the previous article, I had explained the continuous integration CI and setting up the cruise control .net. In this articl

Using NAnt with CCNet

This is the fourth article of the series. In the last article we had seen the usage of MSBuild. In this article we will look at the NAnt. NAnt is free and open source software for automating the build