当每个解决方案有多个测试项目时,DeploymentItem 无法复制目录
我有许多测试类和方法可以复制特定目录,如下所示:
[TestClass, DeploymentItem("LanguageData", "LanguageData")]
public class OcrTests
{
[TestMethod]
public void Can_Capture_Field()
{
// some code that expects the LanguageData directory to be in the test results Out directory
}
// etc
}
[TestClass]
public class OcrBuilderTests
{
[TestMethod, DeploymentItem("LanguageData", "LanguageData")]
public void Can_Build_Specific_Ocr_Engine_Implementation()
{
// some more code that expects the LanguageData directory to be in the test results Out directory
}
// etc
}
这些测试位于单个程序集中,LangaugeData 目录中的所有文件都将其 Copy to Output Directory
设置为 始终复制
。
一切正常,只要我只将一个测试程序集加载到解决方案中,或者这是我运行测试的唯一程序集(即仅运行测试),该目录就会复制到测试结果 Out
目录在当前上下文/类别中)。
一旦我添加第二个程序集并运行解决方案中的所有测试,那么该目录就不再被复制,但任何其他只是单个文件的 DeploymentItem 似乎都可以很好地复制。
测试本身仍然运行,但依赖于该目录的测试崩溃了。大概这是因为 MSTest 找不到该目录 - 也许它期望它位于其他测试程序集之一的构建目录中?
您知道阻止复制的多个测试项目是什么吗?除了将该目录中的每个文件添加为单独的 DeploymentItem 之外,我可以采取哪些措施来解决它?
I have a number of test classes and methods that copy a particular directory like so:
[TestClass, DeploymentItem("LanguageData", "LanguageData")]
public class OcrTests
{
[TestMethod]
public void Can_Capture_Field()
{
// some code that expects the LanguageData directory to be in the test results Out directory
}
// etc
}
[TestClass]
public class OcrBuilderTests
{
[TestMethod, DeploymentItem("LanguageData", "LanguageData")]
public void Can_Build_Specific_Ocr_Engine_Implementation()
{
// some more code that expects the LanguageData directory to be in the test results Out directory
}
// etc
}
Those tests are in a single assembly and all the files in the LangaugeData directory have their Copy to Output Directory
set to Copy Always
.
It all works fine and the directory is copied to the test results Out
directory as long as I only have that one test assembly loaded into the solution or that's the only assembly I run tests from (i.e. run tests only in current context/class).
As soon as I add a second assembly and run all the tests in the solution then that directory no longer gets copied, but any other DeploymentItems that are just individual files seem to get copied fine.
The tests themselves all still run, but the ones that depend on that directory crash. Presumably that's because MSTest can't find the directory - perhaps it's expecting it to be in the build directory of one of the other test assemblies?
Any ideas what it is about multiple test projects that's preventing the copy, and what I can do to get around it, short of adding every single file in that directory as an individual DeploymentItem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试了你的方法,但它仍然没有正确复制文件夹,所以我所做的只是复制文件而不是目录(也许这对某人有帮助):
Tried your approach but still it did not copy folder properly, so what i did instead copied files not directories(maybe this helps someone):
这个问题很老了,但仍然可以使其他人受益。特别是自从我结束在这里:)
似乎
DeploymentItemAttribute
不支持在多个测试类中使用相同的源路径名。注意:我说的是相同的路径名,而不是物理文件夹(认为要部署具有相同文件夹名称的不同测试项目)。
但是,目标文件夹名称可以不同,不会产生不良影响。
我的建议是:
[TestClass, DeploymentItem("LanguageData", "LanguageData")]
OcrTests< /code> 和
OcrBuilderTests
类继承新类。我已经尝试过此操作,并取得了巨大成功。
就我而言,我有一个公共测试装置项目和多个测试项目,每个项目都使用基类。
不幸的是,DeploymentItemAttribute 充满了陷阱,请参阅此处< /a> 了解更多。
This question is quite old, but could still benefit others. Especially since I ended up here :)
It seems that
DeploymentItemAttribute
doesn't support using the same source path name in multiple test classes.Note: I said same path name, not physical folder (think different test projects with same folder name to deploy).
However the destination folder name can be different, with no ill effects.
My suggestion is:
[TestClass, DeploymentItem("LanguageData", "LanguageData")]
OcrTests
andOcrBuilderTests
classes to inherit the new class.I've tried this, with Great Success.
In my case, I had a common test fixture project and multiple test projects, each using the base class.
Unfortunately the DeploymentItemAttribute is filled with Gotchas, see here for more.