views:

477

answers:

3

I'm using NUnit 2.5 and NAnt 0.85 to compile a .NET 3.5 library. Because NAnt 0.85 doesn't support .NET 3.5 out of the box, I've added an entry for the 3.5 framework to NAnt.exe.config.

'MyLibrary' builds, but when I hit the "test" target to execute the NUnit tests, none of them seem to run.

[nunit2] Tests run: 0, Failures: 0, Not run: 0, Time: 0.012 seconds

Here are the entries in my NAnt.build file for the building and running the tests:

<target name="build_tests" depends="build_core">
    <mkdir dir="Target" />
    <csc target="library" output="Target\Test.dll" debug="true">
        <references>
            <include name="Target\MyLibrary.dll"/>
            <include name="Libraries\nunit.framework.dll"/>
        </references>
        <sources>
            <include name="Test\**\*.cs" />
        </sources>
    </csc>

</target>

<target name="test" depends="build_tests">                
    <nunit2>
        <formatter type="Plain" />
        <test assemblyname="Target\Test.dll" />
    </nunit2>
</target>

Is there some versioning issue I need to be aware of? Test.dll runs fine in the NUnit GUI.

The testing dll is definitely being found, because if I move it I get the following error:

Failure executing test(s). If you assembly is not build using NUnit 2.2.8.0... Could not load file or assembly 'Test' or one of its dependencies...

I would be grateful if anyone could point me in the right direction or describe a similary situation they have encountered.

Edit I have since tried it with NAnt 0.86 beta 1, and the same problem occurs.

+1  A: 

I have no experience with manually edited NAnt 0.85 configuration. Perhaps You should try the latest nightly from NAnt (0.86 beta 2). Using this version we build all our .NET 3.5 projects without any complaints.

The Chairman
A: 

For a sanity check, have you made sure to include the appropriate NUnit attributes in your test classes? Those attributes are the hooks by which NUnit determines what classes are test fixtures, and what methods are test cases.

In the past, I've made the mistake to not include appropriate attributes, and run the tests with no apparent result. It's a simple thing, but just making sure.

Grant Palin
A: 

The Nunit2 Nant task is still hardcoded to use the Nunit 2.2 library.

See docs: http://nant.sourceforge.net/release/latest/help/tasks/nunit2.html

"Runs tests using the NUnit V2.2 framework"

You may be able to sort this out with assembly binding redirection, however I think the recommendation is just to use the Nant <exec> task and call the NUnit 2.5 console runner directly.

e.g.:

    <!-- Run Unit Tests under NUnit 2.5 -->
    <exec program="${LibraryPath}\NUnit\2.5.7\nunit-console.exe">
        <arg value="${SourcePath}\ProjectName.Tests\bin\Release\ProjectName.Tests.dll" />
    </exec>

Much simpler anyway.

I am running this through TeamCity and the unit test output seems to still behave correctly.

Nick Meldrum