.net-3.5 - NAnt 没有运行 NUnit 测试

标签 .net-3.5 nunit nant

我正在使用 NUnit 2.5 和 NAnt 0.85 来编译 .NET 3.5 库。因为 NAnt 0.85 不支持开箱即用的 .NET 3.5,所以我在 NAnt.exe.config 中添加了 3.5 框架的条目。

'MyLibrary' 构建,但是当我点击“测试”目标来执行 NUnit 测试时,它们似乎都没有运行。

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

以下是我的 NAnt.build 文件中用于构建和运行测试的条目:
<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>

我需要注意一些版本控制问题吗? Test.dll 在 NUnit GUI 中运行良好。

肯定会找到测试 dll,因为如果我移动它,我会收到以下错误:

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...



如果有人能指出正确的方向或描述他们遇到的类似情况,我将不胜感激。

编辑 我已经用 NAnt 0.86 beta 1 试过了,同样的问题发生了。

最佳答案

Nunit2 Nant 任务仍然被硬编码为使用 Nunit 2.2 库。

参见文档:http://nant.sourceforge.net/release/latest/help/tasks/nunit2.html

"Runs tests using the NUnit V2.2 framework"



您可以通过程序集绑定(bind)重定向来解决这个问题,但是我认为建议只是使用 Nant 任务并直接调用 NUnit 2.5 控制台运行程序。

例如。:
    <!-- 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>

反正简单多了。

我正在通过 TeamCity 运行它,并且单元测试输出似乎仍然正常运行。

关于.net-3.5 - NAnt 没有运行 NUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1975721/

相关文章:

c# - GroupPrincipal.IsMemberOf 始终返回 false

wpf - MVVM WPF 组合框 : creating a template for comboboxitem

visual-studio - NUnit 和 Visual Studio 2008 集成测试可以并行使用吗?

unit-testing - NUnit 没有运行我的测试用例

c# - Moq 具有私有(private)集 : "Invalid setup on a non-virtual" 的虚拟 ICollection<> 属性

visual-studio-2008 - Visual Studio 2008 专业版构建过程

.net - Windows 2003 与 .NET 3.5 SP1 一起崩溃

.net - 有没有办法静默或自动安装 .NET?

nant - 如何从 NANT 返回特定的退出代码?

.net-4.0 - 如何使用 NAnt 定位 .Net 4.0 Beta?