NUnit测试在单独的项目中,相同的解决方案 [英] NUnit tests in a separate project, same solution

查看:80
本文介绍了NUnit测试在单独的项目中,相同的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含我的主项目和一个使用NUnit的测试项目的解决方案.一切都可以编译,但是当我运行NUnit时,在测试加载后会出现以下异常,并且测试失败.我已添加主项目作为参考,并且在外部工具设置中NUnit的参数中有 $(ProjectDir)bin/Debug/$(TargetName)$(TargetExt)空白的初始目录.

I have a solution containing my main project and a test project using NUnit. Everything compiles but when I run NUnit I get the exception below after the tests load, and the tests fail. I've added the main project as a reference, and I have $(ProjectDir)bin/Debug/$(TargetName)$(TargetExt) in the arguments for NUnit in the external tools setup, with a blank initial directory.

MyMainProjectTests.Database.TestAddDelete:   
System.BadImageFormatException : Could not load file or assembly 'MyMainProject, 
    Version=1.1.1.0, Culture=neutral, PublicKeyToken=null' or one of its 
    dependencies. An attempt was made to load a program with an incorrect format.
TearDown : System.Reflection.TargetInvocationException : Exception has been 
    thrown by the target of an invocation.
  ----> System.BadImageFormatException : Could not load file or assembly 
    'ChickenPing, Version=1.1.1.0, Culture=neutral, PublicKeyToken=null' or one 
    of its dependencies. An attempt was made to load a program with an incorrect 
    format.

经过数小时的搜索,我发现的唯一发现是VS2005中的错误,其中提到了/bin和/obj目录,但提供的答案没有帮助.

After scouring for hours the only thing I've found is a bug in VS2005 which mentions the /bin and /obj directories, but the answer provided didn't help.

有解决方案吗?

推荐答案

我将单元测试项目设置为StartUp项目,而不是将NUnit设置为外部工具.在项目的属性"屏幕中,将启动操作"设置为启动外部程序",并将其指向nunit.exe.在启动选项"部分中,我在命令行参数"框中指定测试程序集(无需路径).此时,只需按 F5 即可启动NUnit.

Instead of setting up NUnit as an External Tool, I set the unit test project as the StartUp project. In the project's Properties screen, set the Start Action to "Start external program" and point it to nunit.exe. In the Start Options section, I specify the test assembly (no path necessary) in the "Command line arguments" box. At this point, simply press F5 to start up NUnit.

这篇关于NUnit测试在单独的项目中,相同的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆