Matthijs Wessels
Matthijs Wessels

Reputation: 6729

How can I let CruiseControl.NET/nant run all Unittest projects postfixed with .Test?

In our continuous integration setup, I would like to set up CruisControl.NET to automatically run all our unittests. However, I don't want to have to specify every unittest dll seperately in the configuration.

All the unittest projects are all postfixed with .Test (and all non-unittest projects are not). How can I configure CruiseControl.NET to run all the unittests from these projects (I am using v1.5.7256.1 of CruiseControl.NET)?

My current config attempt:

<nunit>
    <path>$(nunit.path)</path>
    <assemblies>
        <assembly>$(working.dir)\**\*.Test.dll</assembly>
    </assemblies>
</nunit>

I'm finding it very difficult to find documentation on this specific nunit element. Most pages I can find talk about using exec, nunit2 or another nunit element or the nunit-console commandline options.

I don't have much experience with managing the build environment and am working on an existing configuration where every assembly was specified separately in the following manner.

<nunit>
    <path>$(nunit.path)</path>
    <assemblies>
        <assembly>$(artifact.dir)\test1.dll</assembly>
        <assembly>$(artifact.dir)\test2.dll</assembly>
    </assemblies>
</nunit>

Hence my failed attempt using wild cards.

EDIT:

Here is some extra xml of my configuration file to show the context a little bit:

<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
    <project name="MyProject">
        <!-- whole bunch of other elements -->
        <tasks>
            <nunit>
                <!-- see above -->
            </nunit>
        </tasks>
    </project>
</cruiscontrol>

After Mightmuke's suggestion, I tried replacing the <nunit> element with his suggestion, but got the following exception: Unable to instantiate CruiseControl projects from configuration document. Configuration document is likely missing Xml nodes required for properly populating CruiseControl configuration. Unable to load array item 'property' - Cannot convert from type System.String to ThoughtWorks.CruiseControl.Core.ITask for object with value: ""

Then I tried to move the <property> and <foreach> element outside the element. Then I get the exception: Unused node detected: <property name="nunit.filelist" value="" />

I'm now trying to find out more about the <foreach> element and where I can put that, but somehow I find it hard to find any documentation about it.

EDIT2:

I found the documentation of the nunit task I'm using: http://ccnet.sourceforge.net/CCNET/NUnit%20Task.html

I specifies the element to be of type String[]. I'm not sure what that means... but it seems from the example that it just means that it must contain a list of child elements of the same name in Singular form.


PS: I realize this question is getting a bit out of hand... When the whole thing is solved, I'll try to edit it in such a format so that it might be useful to someone else later.

Upvotes: 1

Views: 1134

Answers (1)

Mightymuke
Mightymuke

Reputation: 5144

This is an example configuration if you were to use the nunit console.

<property name="nunit.filelist" value="" />
<foreach item="File" property="testfile" verbose="true">
  <in>
    <items basedir=".">
      <include name="${working.dir}\**\*.Test.dll" />
    </items>
  </in>
  <do>
    <property name="nunit.filelist" value="${nunitfile.list + ' ' + testfile}" />
  </do>
</foreach>

<exec program="nunit-console-x86.exe" failonerror="true" verbose="true">
  <arg value="${nunit.filelist}" />
  <arg value="/xml=nunit-results.xml" />
  <arg value="/nologo" />
  <arg value="/nodots" />
</exec>

This hasn't been tested, and there are likely better ways to skin it, but it will hopefully provide a starting point for you.

Upvotes: 1

Related Questions