MSTest VS2010 - DeploymentItem将文件复制到不同机器上的不同位置

发布于 2024-09-05 21:55:45 字数 840 浏览 2 评论 0原文

我发现

[TestClass(), DeploymentItem(@"TestData\")]

当在不同的机器上构建和运行测试时,DeploymentItem 不会将我的测试数据文件复制到同一位置。

测试数据文件被复制到我机器上测试项目中的“bin\debug”目录,但在我朋友的机器上,它们被复制到“TestResults\name_machine YY-MM-DD HH_MM_SS\Out ”。

我的机器上的 bin\debug 目录可以通过以下代码获取:

string appDirectory = 
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

在我朋友的电脑上,相同的代码将返回 TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out

但这并不是真正的问题。问题是我制作的测试数据文件有一个文件夹结构,并且此文件夹结构仅在复制到 bin\debug 时在我的计算机上保留,而在我朋友的计算机上仅将文件添加到 TestResults\ *name_machine YY-MM-DD HH_MM_SS*\Out 目录。这意味着测试将在我的机器上通过,而在他的机器上失败!

有没有办法确保 DeploymentItem 始终复制到 bin\debug 文件夹?或者有一种方法可以确保 DeploymentItem 将文件复制到 TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out 文件夹时保留文件夹结构?

I have found that DeploymentItem

[TestClass(), DeploymentItem(@"TestData\")]

is not copying my test data files to the same location when tests are built and run on different machines.

The test data files are copied to the "bin\debug" directory in the test project on my machine, but on my friend's machine they are copied to "TestResults\name_machine YY-MM-DD HH_MM_SS\Out".

The bin\debug directory on my machine can be obtained with the code:

string appDirectory = 
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

and the same code will return TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out on my friends PC.

This however isn't really the problem. The problem is that the test data files I have made have a folder structure, and this folder structure is only maintained on my machine when copied to bin\debug, whereas on my friends machine only the files are added to the TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out directory. This means that tests will pass on my machine and fail on his!

Is there a way to ensure that DeploymentItem always copys to the bin\debug folder? Or a way to ensure that the folder structure will be retained when DeploymentItem copies the files to the TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out folder?

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

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

发布评论

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

评论(1

慕巷 2024-09-12 21:55:45

玩了一段时间后,看起来最好的处理方法是确保对于每个子目录,添加一个新的 DeploymentItem,确保指定“outputDirectory”,如下所示:

[TestClass(), DeploymentItem("TestData\\", "TestData"),
DeploymentItem(@"TestData\\SubDir\\", "TestData\\SubDir")]

这允许测试在你的机器 - 希望这对某人有帮助!

After playing around for a while, it looks like the best way to deal with it is to ensure that for every subdirectory, you add a new DeploymentItem making sure that you specify the "outputDirectory", like so:

[TestClass(), DeploymentItem("TestData\\", "TestData"),
DeploymentItem(@"TestData\\SubDir\\", "TestData\\SubDir")]

This allows the tests to run on your machine - hope this helps someone!

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