DeploymentItem无法复制目录时有每个解决方案多个测试项目 [英] DeploymentItem fails copying directories when there are multiple test projects per solution

查看:241
本文介绍了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
}

这些测试是在一个单一的组装和在LangaugeData目录中的所有文件都有自己的复制到输出目录设置为复制始终

这一切工作正常,只要我只有一个测试组件加载到解决方案,或者说是唯一集的目录复制到测试结果退出目录我从运行(即运行测试只有在目前的情况下/班)的测试。

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).

当我添加第二个组装和运行所有测试的解决方案,则该目录将不再被复制,,但的任何其他DeploymentItems这只是单个文件似乎被复制的罚款。

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.

测试本身都还在运行,但依赖于该目录崩溃的人。 presumably这是因为MSTest的找不到目录 - 也许是期待它在其他测试组件之一的构建目录

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?

任何的想法是什么一回事多个测试项目,这是preventing的副本,我能做些什么来解决它,短期增加的每一个文件在该目录作为个人DeploymentItem的?

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?

推荐答案

这个问题是很老,但仍然可以惠及他人。特别是由于的 I 的结束位置:)

This question is quite old, but could still benefit others. Especially since I ended up here :)

看来, DeploymentItemAttribute 不支持在多个测试类使用相同的源路径名。 注意:我说相同的路径名,而不是物理文件夹(想不同的测试项目相同的文件夹名称部署)

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.

我的建议是:

  1. 创建一个固定的基类(如果你preFER,在不同的项目)
  2. 添加属性: [TestClass的,DeploymentItem(LanguageData,LanguageData)]
  3. 更改 OcrTests OcrBuilderTests 类继承的新类。
  4. 记住用来删除OcrTests和OcrBuilderTestsLanguageData
  5. 的deploymentitem属性
  1. Create a fixture base class (if you prefer, in separate project)
  2. Add the attribute: [TestClass, DeploymentItem("LanguageData", "LanguageData")]
  3. Change your OcrTests and OcrBuilderTests classes to inherit the new class.
  4. Remember to remove the deploymentitem attributes for 'LanguageData' from OcrTests and OcrBuilderTests

我想这一点,大获成功。 就我而言,我有一个共同的测试夹具项目和多个测试项目,每个项目使用的基类。

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.

不幸的是,DeploymentItemAttribute充满技巧,见这里更多。

Unfortunately the DeploymentItemAttribute is filled with Gotchas, see here for more.

这篇关于DeploymentItem无法复制目录时有每个解决方案多个测试项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆