How to run NUnit v2.4.8 tests with NAnt 0.86 beta?
Asked Answered
A

1

6

I tried recently to use NAnt (beta 0.86.2962.0) to run some unit tests compiled with the last stable version of NUnit (v2.4.8) without any success.

The error I get is the following :

[nunit2] Assembly "C:\Dev\MySample\bin\tests\My.Sample.Tests.dll" contains no tests.

Of course, the assembly contains tests that I can run from any runner, like NUnit one, TestDriven or Resharper. I would like to use <nunit2> task, and not directly the <exec> one, but I'm wondering if it is still possible, even using app.config files to bind assembly versions.

Airs answered 5/9, 2008 at 8:14 Comment(0)
P
10

I can't remember why, but I gave up on using the <nunit2> task and I've been using the <exec> task and nunit-console.exe happily. If it helps, here's my test target that runs NUnit and FxCop. Note that it skips them if the executables aren't in the Windows path.

<target name="test" description="Run unit tests" depends="build">
  <property name="windows-path" value="${string::to-lower(environment::get-variable('PATH'))}"/>
  <property name="nunit-in-path"
      value="${string::contains(windows-path, 'nunit')}"/>
  <echo message="Tests skipped because no NUnit folder was found in the Windows path."
      unless="${nunit-in-path}"/>
  <exec program="nunit-console.exe" if="${nunit-in-path}">
      <arg file="../MyProject/MyProjectTest.nunit"/>
  </exec>
  <property name="fxcop-in-path"
      value="${string::contains(windows-path, 'fxcop')}"/>
  <echo message="FxCop skipped because no FxCop folder was found in the Windows path."
      unless="${fxcop-in-path}"/>
  <fxcop projectFile="../MyProject/MyProject.fxcop" directOutputToConsole="true" 
      failOnAnalysisError="true" if="${fxcop-in-path}"/>
</target>
Purple answered 1/10, 2008 at 19:58 Comment(4)
I second this...I used to try and do the app.config magic to try and get the nunit2 task to work but gave up a while back and now use the exec task as described above.Tsarism
Don, Andy: I believe a good reason to use <exec> task instead of <nunit2> is, if your test suite has tests marked with [ExpectedException] and the exception is actually thrown, the <nunit2> NAnt task reports it as a failure instead of success and the build fails. I'm having this problem right now. I'm going to solve it by using <exec>, but will of course appreciate another workaround advice.Firstborn
HI guys, I am trying to use my unit test dll in arg file. But it is not saying which tests failed. The arg tag doesn't have verbose or fail on error so how would you find out whether your tests failed or passed?Driver
I think nunit-console sets the return value to non-zero if any of the tests fail, and that should cause the build to fail, @alice7. I think it also writes messages to stdout for any failed tests. If you're not seeing that, then I suspect something else is wrong. Try running nunit-console at a command prompt so you can clearly see what the output is. Nant might not be able to find nunit-console.exe, or NUnit might not be able to find your test DLL. If that doesn't help, then I suggest you ask a separate question with as much detail as you can provide.Purple

© 2022 - 2024 — McMap. All rights reserved.