从自动化测试中获取程序集的目录

发布于 2024-12-24 01:54:08 字数 783 浏览 2 评论 0 原文

我正在尝试编写集成测试来覆盖我的应用程序的大型重构(我想编写单元测试,但它距离可单元测试还很远)。我正在使用 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随遇而安 2024-12-31 01:54:08

您需要在 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

小姐丶请自重 2024-12-31 01:54:08

当我使用 Resharper 调试测试时,使用两种方法都会得到类似的结果:

C:\Documents and Settings\Tomas\Local Settings\Temp\0xl3rbd5.4qn\MGClient.Test\assembly\dl3\2a373977\60b182bb_e5c9cc01\DRA.config

在 NUnit 测试加载器设置 - 高级

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

Switch off shadow copy in NUnit Test Loader Settings - Advanced

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文