【发布时间】:2013-06-28 20:01:51
【问题描述】:
我将使用nunit-console 来运行我的解决方案中的所有测试。
我这样做了:
c:\some\path>nunit-console-x86.exe MySolution.sln
NUnit-Console version 2.6.2.12296
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
CLR Version: 2.0.50727.5466 ( Net 3.5 )
ProcessModel: Default DomainUsage: Default
Execution Runtime: net-3.5
Could not load file or assembly 'MyNamespace.Administration, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
所以,我决定尝试nunit-x86.exe 我做了 File > Open Project > MySolution.sln 并得到了这个:
---------------------------
NUnit
---------------------------
Test load failed!
System.IO.FileNotFoundException : Could not load file or assembly
'MyNamespace.Administration, Version=0.0.0.1, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot
find the file specified.
For further information, use the Exception Details menu item.
---------------------------
OK
---------------------------
The exception can be found here
发生了什么,我该如何解决?(无需维护 MySolution.nunit 文件)
更多信息
-
MyNamespace.Administration甚至不是包含测试的 dll 之一,这意味着 nunit 无法尝试加载它以查找要运行的测试。知道这一点后,我编辑了nunit-x86.exe(MySolution.nunit) 创建的文件,并删除了所有没有测试的 dll。果然,测试工作(在 gui 和控制台中)。这对我来说是不可接受的,因为这意味着我必须保留另一个配置文件。 Nunit 支持 .sln 文件应该可以避免这种情况。 - 我的测试使用 TestDriven.Net 运行良好(但我确实需要使用 nunit-console 运行它们)
-
我查看了this answer,但我无法理解融合日志查看器所说的内容。发布该日志会有帮助吗?程序集绑定日志查看器,列出了正在创建的 3 个文件:- nunit-agent-x86.exe,这个好像是在找
MyNamespace.Administration.dll/EXEinside the nunit directories - Tests_24398275 x2 - 一个在我的项目文件夹中查找 nunit.core,另一个在我的项目文件夹中查找 unit.core.interfaces。我不会注意这两个,因为它们也出现在我手动编辑的 .nunit 项目中)。
- nunit-agent-x86.exe,这个好像是在找
- (根据 andreister 的评论)问题似乎出在项目/程序集本身,而不是创建方法。如果我创建一个 .nunit 项目并尝试向其中添加
MyNamespace.Administration(使用“添加程序集...”或“添加 VS 项目...”),它会失败。 - 直接调用
nunit-console-x86 somepath/bin/Debug/MyNamespace.Administration.dll可以。
【问题讨论】:
-
显然,
MyNamespace.Administration.dll包含测试使用的代码。你确定你没有忘记,例如,在引用项目时输入CopyLocal=True? -
它被一个测试项目 (dll) 引用,但是当我使用 MySolution.nunit 时该项目可以工作,这让我相信它真的无法尝试加载该项目以查看它是否有测试(我假设它会打开项目以查看哪些有测试)。
-
如何将该项目显式添加到
.nunit,看看它是否会失败?通常对于非测试项目,NUnit 只会报告它没有测试。 -
@andreister 更新了问题
-
确定 .NET 版本没问题?您不会将 .NET4 程序集馈送到较旧的 NUnit 中吗?也许尝试一个干净的构建。并尝试从
Administration.dll中删除依赖项,然后开始一一添加,看看是否有区别。
标签: nunit nunit-console