Andrew Stopford's Weblog

poobah

Sponsors

News

Articles

Family

Old Blogs

MbUnit & NAnt update

While trying to figure out why the recommend syntax for MbUnit in NAnt did'nt work I started working on my own NAnt task for MbUnit but figured it out in the end, what follows is a in depth guide to some internals, here goes.

Creating a NAnt task is very simple, a guide to creating a simple one can be found here. I built my task using VB.NET and ported the code over, watch for syntax and other errors in your code as NAnt will simply report that your taskk type cannot be loaded (even verbose mode), any indications on error reporting/catching in the NAnt API would be handy.

The ExecuteTask is a key method in a NAnt task and this gave me my starting point to inspect the MbUnit task source to see what was going on. A key type that the ExecuteTask method uses is the MbUnit type. This exposes several NAnt types one of which is the NAnt.Core.Types.FileSet which is exposed its self within the assemblies property. This is used to load assemblies into NAnt. The MbUnit type is exposed in a buildfile as a <test> attribute so this concludes me to reach the following.

<mbunit>
  <fileset>
    <includes asis="true" name="TestCode.dll" />
  </fileset>
</mbunit>

As reported to be correct syntax and generated by the MbUnit GUI but the syntax I suspect should read.

<mbunit>
  <test>
 <assemblies>
      <includes asis="true" name="TestCode.dll" />
 </assemblies>
  </test>
</mbunit>

You also need to copy the following MbUnit DLLs into the NAnt bin directory.

  • MbUnit.Core.dll
  • MbUnit.Framework.dll
  • MbUnit.Tasks.dll
  • Quickgraph.dll
  • QuickGraph.Algorithms.dll

This runs the tests (more progress than last night) but after the tests have been marked as complete the following happens.

System.NullReferenceException: Object reference not set to an instance of an obj
ect.
   at MbUnit.Core.Reports.ReportBase.GetFileName(ReportResult result, String out
putPath, String nameFormat, String extension) in C:\svnhome\trunk\MbUnit\MbUnit.
Core\Reports\ReportBase.cs:line 49

this was present in TestDriven.NET-1.0.855d.zip as taken from the automated build page. Tracing this back it seems that the result object is not being created, this is being returned from the quickgraph assemblies so after a successful pass should be ok. I going to continue to see how far I can get with creating my own light weight version of a NAnt task for MbUnit, this would help me debug whats going on. Thoughts welcome?

Update:

I saw a tip (can't find where I located it) that the NUnit2 task syntax will work with MbUnit so I altered such a build file, MbUnit raised an error as reported in this bug report (raised on the 11th November).  I just have to wait for the fix now or dig in some more and figure out why this might be occuring.

Comments

Jonathan de Halleux said:

Hi Andrew,

I'm currently addind tests for the NAnt task. I finished the tests for MSBuild yesterday and I hope to fix this damn to fix this damn NAnt task tonight.

When I introduced assembly dependencies, this was a major refactoring and I did not have tests, so now the first step is takened, my tests are red. Just need the time to make them green again.
# November 16, 2004 1:14 PM

hants said:

you should add report file attribute:

<project>

   <target name="tests">

     <mbunit

         report-types="Text;Html;Dox;Xml"

         report-filename-format="myformat{0}{1}"

         report-output-directory="put\it\there"

         >

         <assemblies>

             <includes name="*.Tests.dll" />

    </assemblies>

    </mbunit>

   </target>

 </project>

hope that can help you

# August 27, 2006 11:00 AM