如何让nunit-console查找\bin\Debug中的程序集而不是\bin\x86\Debug?

4

我正在尝试搭建一个构建机器,并希望从批处理脚本中运行nunit(在几个相对较大且动态的解决方案上)。我运行了以下命令行:

"C:\Program Files (x86)\NUnit 2.6.1\bin\nunit-console-x86.exe" "C:\MySolutionPath\MySolution.sln"
"C:\Program Files (x86)\NUnit 2.6.1\bin\nunit-console.exe" "C:\MySolutionPath\MySolution.sln"

两者都报出了System.IO.DirectoryNotFoundException异常:

NUnit-Console version 2.6.1.12217
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.5456 ( Net 3.5 )

ProcessModel: Default    DomainUsage: Default
Execution Runtime: net-3.5
Unhandled Exception:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\MyProjectPath\bin\x86\Debug\MyAssembly.dll'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean
 useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, St
ring msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at NUnit.Core.AssemblyReader.CalcHeaderOffsets()
   at NUnit.Core.AssemblyReader..ctor(String assemblyPath)
   at NUnit.Util.RuntimeFrameworkSelector.SelectRuntimeFramework(TestPackage package)
   at NUnit.Util.DefaultTestRunnerFactory.GetTargetProcessModel(TestPackage package)
   at NUnit.Util.DefaultTestRunnerFactory.MakeTestRunner(TestPackage package)
   at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
   at NUnit.ConsoleRunner.Runner.Main(String[] args)

对我来说,它看起来好像在错误的文件夹中查找:
C:\MyProjectPath\bin\x86\Debug\MyAssembly.dll

应该是

C:\MyProjectPath\bin\Debug\MyAssembly.dll

有没有办法在NUnit中指定这个(或者必须在解决方案中)?
2个回答

2
您可以将测试装配路径作为参数传递,而不是解决方案文件:
"C:\Program Files (x86)\NUnit 2.6.1\bin\nunit-console-x86.exe" "C:\MyProjectPath\bin\Debug\MyAssembly.dll"

3
我不想这么做。我有成百上千个项目。我希望它能动态地找到解决方案中的项目,然后根据这些进行测试。 - André C. Andersen
@AndréChristofferAndersen 看起来它把解决方案文件当作项目文件来处理。我不确定你想做什么是否可能。也许你可以使用NUnit项目 - Ufuk Hacıoğulları
我可能误解了。我以为可以让nunit-console.exe运行与解决方案文件相关的所有单元测试。也许我的问题正在演变成:“如何从命令行运行解决方案中的所有nunit测试”。 - André C. Andersen
@AndréChristofferAndersen 那样会更准确。 - Ufuk Hacıoğulları
2
我一直在研究这个问题,看起来你应该能够使用nunit-console.exe运行一个解决方案文件(sln)。通过将项目设置为在“任何CPU”上运行,我解决了DirectoryNotFoundException的问题。现在我遇到了另一个问题,这是明天的事情了。谢谢你的时间,Ufuk。 - André C. Andersen

0

不知道是否可以实现,但我认为大多数构建服务器都可以为您完成此操作。 TeamCity可以做到这一点,我相信其他的也可以。 TeamCity非常好用且免费(在某个项目限制范围内)。


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