与DeploymentItem属性问题 [英] Problems with DeploymentItem attribute

查看:466
本文介绍了与DeploymentItem属性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写保持在C#.net一个老的系统,删除一些过时的特点,做一些重构。感谢神,previous家伙写了一些单元测试(MSTests)。我和JUnit测试很舒服,但并没有太多与MSTests做呢。

I'm currently maintaining an "old" system written in C#.net, removing some obsolete features and doing some refactoring. Thanks god, the previous guy wrote some unit tests (MSTests). I quite comfortable with JUnit tests, but didn't do yet much with MSTests.

的测试方法有一个 DeploymentItem 属性,指定它是由被测试业务逻辑方法和第二 DeploymentItem解析文本文件,即只有一个路径已经包含了一堆那必须得部署TIF文件中指定。

The test methods have a DeploymentItem attribute, specifying a text file which is parsed by the business logic method that is being tested and a 2nd DeploymentItem where just a path has been specified containing a bunch of TIF files that have to be deployed too.

[TestMethod()]
[DeploymentItem(@"files\valid\valid_entries.txt")]
[DeploymentItem(@"files\tif\")]
public void ExistsTifTest()
{
   ...
}

测试工作过,但现在我不得不改变包含在\\文件TIF文件的名称\\目录TIF。根据规则,在文件名TIF必须匹配特定的模式也是由该 ExistsTifTest()方法检查。
现在,我不得不改变文件名,以使其适应新的要求和suddently的TIF文件都没有更多的部署前。

The tests worked before, but now I had to change the names of the TIF files contained in the \files\tif directory. According to a rule, the TIF filenames have to match a certain pattern which is also checked by the ExistsTifTest() method. Now I had to change the filenames in order to adapt them to the new requirements and suddently the TIF files are no more being deployed as before.

有人可以给我一个提示,为什么出现这种情况或者可能是什么原因?同样的事情也发生了,如果我添加一个新的文本文件说my2ndTest.txt中的\\文件中的valid_entries.txt旁边\\用的测试方法根据DeploymentItem属性有效\\目录下。该文件没有得到部署?

Can someone give me a hint why this happens or what may be the cause? The same thing happens also if I add a new text-file say "my2ndTest.txt" beside the "valid_entries.txt" in the \files\valid\ directory with the according DeploymentItem attribute on the test method. The file doesn't get deployed?

我现在直接在testrunco​​nfig定义部署路径部署的图像,但我想知道为什么这些事情发生或为什么例如我新文件my2ndTest.txt没有得到部署,而其他人做的。

I got the images now deployed by defining the deployment path directly in the testrunconfig, but I'd like to understand why these things happen or why for instance my new file "my2ndTest.txt" doesn't get deployed while the others do.

非常感谢。

推荐答案

DeploymentItem 是一个有点乱。

在您的解决方案将有一个复制到输出文件夹,在VS.NET设置每个文件。你需要这是复制始终(或类似),以获得这些文件到输出文件夹。

Each file in your solution will have a "Copy To Output Folder" setting in VS.NET. You need this to be "Copy Always" (or similar) in order to get the files into the output folder.

请检查您是否已经有了这套新的文件。如果你没有这一套则文件不会被复制到输出文件夹,然后他们无法从输出文件夹被部署到MSTest的做它的东西。

Check that you've got this set for the new files. If you don't have this set then the files won't get copied to the output folder, and then they can't be deployed from the output folder to the folder where MSTest does it stuff.

个人而言,如果我有我需要为我的单元测试,我发现,这些嵌入文件作为资源转化为一个程序集,并且具有测试期间集结号解包本身就是一个更predictable方式文件做事。情况因人而异。

Personally, if I have files that I need for my unit tests I've found that embedding those files as resources into an assembly, and having that assembly "unpack" itself during the tests is a more predictable way of doing things. YMMV.

注意:这些意见是根据我的经验,VS2010。评论我的回答会认为,这是不是与VS2012的问题。我仍然站在注释,使用嵌入的资源涉及较少的神奇,对我来说,使安排的我的单元测试阶段更明确。

note: These comments are based upon my experience with VS2010. Comments to my answer would suggest that this is not problem with VS2012. I still stand by comments that using embedded resources involves less "magic" and, for me, makes the "arrange" stage of my unit tests much more explicit.

这篇关于与DeploymentItem属性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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