使用 NAnt 在 NUnit 测试中运行 TestCase 属性

3
我曾使用这个nant任务来运行我的nunit测试。
<nunit2 failonerror="false">
  <formatter usefile="true"
             outputdir="build"
             type="Xml"
             extension=".xml"/>
  <test>
    <assemblies>
      <include name="Build/*.Tests.dll"/>
    </assemblies>
    <references >
      <include name="Tools/**/*.dll"/>
      <include name="Build/*.dll"/>
    </references>
  </test>
</nunit2>

它有一个好处,就是我可以在多个项目中使用它而不需要更改任何内容。问题是,它似乎忽略了一些测试中的TestCaseExpectectException属性,导致它们失败了。我看到了使用exec任务来调用nunit-console.exe的建议,但这意味着我必须单独指定所有测试dll。这意味着我不能再在所有项目中使用它而不必编辑它。我还必须在我的解决方案中添加测试项目时随时编辑它。
有没有办法兼顾两全?
1个回答

2

您可以使用<foreach>来运行测试:

<foreach item="File" property="test-assembly">
  <in>
    <items>
      <include name="${binaries-dir}/*" />
    </items>
  </in>
  <do>
    <exec program="${nunit.exe}" workingdir="${binaries-dir}"
        managed="true">
      <arg value="/nologo" />
      <arg value="${test-assembly}" />
    </exec>
  </do>
</foreach>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接