在哪里放置单元测试的测试文件

发布于 2024-09-12 07:37:37 字数 442 浏览 0 评论 0原文

我正在编写一些单元测试,我需要能够访问外部文件。我假设我可以将文件放入我的解决方案中,将其标记为复制到输出目录,然后通过相对路径访问它。不幸的是,单元测试似乎是在一个奇怪的目录中运行的。

因此,不是从: 运行,而是

[MyUnitTestProjectFolder]\bin\Release

从: 运行:

[MySolution]\\[TheProjectI'mTesting]\TestResults\\[MyUsername]_[MyComputerName] [DateTimeStamp]\Out

我的问题是,如何设置对单元测试中需要使用的外部文件的访问?

请注意,这些文件不是文本文件。它们是专有的平面文件数据库格式(从另一个应用程序创建),因此在测试运行期间“即时”准备这些文件是不可行的。

I am writing some unit tests and I need to be able to access an external file. I assumed I could just place the file in my solution, mark it to be copied to the output directory, and then access it via a relative path. Unfortunately, it seems that unit tests are run in a strange directory.

So, instead of running from:

[MyUnitTestProjectFolder]\bin\Release

it runs from:

[MySolution]\\[TheProjectI'mTesting]\TestResults\\[MyUsername]_[MyComputerName] [DateTimeStamp]\Out

My question is, how do I set up access to external files I need to utilize from my unit tests?

Note, the files aren't text files. They are a proprietary flat-file database format (created from another application), so preparing these files "on the fly" during the test run is not feasible.

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

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

发布评论

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

评论(1

め可乐爱微笑 2024-09-19 07:37:38

您可以通过测试运行配置来执行此操作:打开测试菜单,“编辑测试运行配置”,选择要编辑的测试配置,然后选择“部署”视图。您可以在此处添加需要部署的任何额外文件。

或者,您可以使用 测试中的 DeploymentItem 属性。

我看过 Visual Studio 2008,但我认为 Visual Studio 2010 中也存在相同的功能。

You can do this via test run configurations: Open the Test menu, "Edit Test Run Configurations", choose a test configuration to edit, and select the "Deployment" view. Here you can add any extra files that need to be deployed.

Alternatively, you can use the DeploymentItem attribute on your tests.

I've looked at visual studio 2008, but I assume the same features exists in visual studio 2010.

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