2011-09-08 56 views
3

我正在使用这个nant任务进行我的nunit测试。使用TestNase属性从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。这意味着我无法在所有项目中使用它,而无需对其进行编辑。无论何时,我都可以在我的解决方案中添加测试项目时编辑它。

有没有什么办法让两全其美?

回答

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> 
+0

感谢。这正是我所期待的。 – scott