如何使用NAnt 0.86 beta运行NUnit v2.4.8测试?

Rom*_*ier 6 .net nant nunit unit-testing

我最近尝试使用NAnt(beta 0.86.2962.0)运行一些使用NUnit(v2.4.8)的最后一个稳定版本编译的单元测试,但没有任何成功.

我得到的错误如下:

[nunit2]程序集"C:\ Dev\MySample\bin\tests\My.Sample.Tests.dll"不包含任何测试.

当然,程序集包含可以从任何运行程序运行的测试,例如NUnit one,TestDriven或Resharper.我想使用<nunit2>任务,而不是直接使用<exec>,但我想知道它是否仍然可行,甚至使用app.config文件来绑定程序集版本.

Don*_*kby 10

我不记得为什么,但我放弃了使用<nunit2>任务,我一直在愉快地使用<exec>任务和nunit-console.exe.如果它有帮助,这是我的测试目标运行NUnit和FxCop.请注意,如果可执行文件不在Windows路径中,则会跳过它们.

<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>
Run Code Online (Sandbox Code Playgroud)

  • Don,Andy:我认为使用<exec>任务代替<nunit2>的一个很好的理由是,如果你的测试套件有[ExpectedException]标记的测试并且实际抛出了异常,那么<nunit2> NAnt任务会将其报告为失败而不是成功,构建失败.我现在遇到这个问题.我将使用<exec>解决它,但当然会欣赏另一个解决方法的建议. (2认同)