我正在尝试编写集成测试来覆盖我的应用程序的大型重构(我想编写单元测试,但它距离可单元测试还很远)。我正在使用 Visual Studio 2010 SP1、Resharper 和 NUnit。
我当前的问题是我找不到一致的方法来获取执行程序集的目录;我尝试的两种方法在单独运行应用程序或从 Visual Studio 调试时有效,但在从 NUnit 或 Resharper 运行测试时失败。
这是代码(VB.NET):
'Method 1
Core.ConfigFile = My.Application.Info.DirectoryPath + "\" + DRA_CONFIG_FILE
'Method 2
Core.ConfigFile = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) + "\" + DRA_CONFIG_FILE
当我使用 Resharper 调试测试时,两种方法都会得到类似的结果:(
C:\Documents and Settings\Tomas\Local Settings\Temp\0xl3rbd5.4qn\MGClient.Test\assembly\dl3\2a373977\60b182bb_e5c9cc01\DRA.config
应该是 D:\SVN.DRA.WorkingCopy\DRA.Test\Integration\MGClient.Test\ bin\Debug\DRA.config)
如何获得正确的路径?
I'm trying to write integration tests to cover a big refactoring of my application (I'd like to write unit tests but it's quite far from being unit testable). I'm using Visual Studio 2010 SP1, Resharper and NUnit.
My current problem is that I can't find a consistent way to obtain the executing assembly's directory; the two methods I tried work when running the application on its own, or when debugging from Visual Studio, but they fail when running the test from NUnit or Resharper.
Here's the code (VB.NET):
'Method 1
Core.ConfigFile = My.Application.Info.DirectoryPath + "\" + DRA_CONFIG_FILE
'Method 2
Core.ConfigFile = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) + "\" + DRA_CONFIG_FILE
When I debug the test using Resharper, I get something like this, with both methods:
C:\Documents and Settings\Tomas\Local Settings\Temp\0xl3rbd5.4qn\MGClient.Test\assembly\dl3\2a373977\60b182bb_e5c9cc01\DRA.config
(it should be D:\SVN.DRA.WorkingCopy\DRA.Test\Integration\MGClient.Test\bin\Debug\DRA.config)
How can I get the correct path?
发布评论
评论(2)
您需要在 Resharper 中禁用卷影复制:
Visial Studio 菜单 ->重新磨刀->选项->工具->单元测试
取消选择正在测试的卷影复制程序集
You need to disable shadow copying in Resharper:
Visial Studio menu -> Resharper -> Options -> Tools -> Unit-Testing
Deselect Shadow-copy assemblies being tested
在 NUnit 测试加载器设置 - 高级
Switch off shadow copy in NUnit Test Loader Settings - Advanced