是什么`DeploymentItem`属性是什么意思? [英] What does `DeploymentItem` attribute mean?

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

问题描述

让我们说我们有一个简短的程序:

Let's say we have a short program:

namespace ConsoleTryIt
{
    static class Program
    {
        static void Main(string[] args)
        {
            var sum = Add(1, 2);
        }

        private static int Add(int p, int p2)
        {
            return p + p2;
        }
    }
}

在创建这个类的单元测试类,Visual Studio中创建一个属性上的测试方法 DeploymentItem 。我看了MSDN这个属性,但仍然没有得到这意味着什么。

When create the unit test class for this class, Visual Studio create a test method with the attribute DeploymentItem. I read MSDN about this attribute but still don't get what it means.

/// <summary>
///A test for Add
///</summary>
[TestMethod()]
[DeploymentItem("ConsoleTryIt.exe")]
public void AddTest()
{
    var expected = 122;
    var actual = Program_Accessor.Add(1, 121);
    Assert.AreEqual(expected, actual);
}

如果你的想法,请分享!

If you get the idea, please share!

谢谢大家对你的答案。这样的想法是要复制的参数,测试环境现状的文件夹中给出的项目。我的下一个问题是:为什么这个方法需要这个属性,有些却没有结果?
我想这是涉及到对被测试类,但没有明确的对我的私有成员。

Thanks everyone for your answers. So the idea is to copy the item given in the argument to the testing evironment's folder. My next question is: why does this method need this attribute while others don't?
I guess it's related to the private members on the tested class but nothing clear to me.

请继续讨论。

推荐答案

本规定由特定的测试所需的文件。测试系统创建其中测试是从运行新的目录。有了这个特性,可以使测试系统特定的文件复制到新目录中。

This specifies files that are required by the specific test. The test system creates a new directory where the tests are run from. With this attribute, you can make the test system copy specific files to that new directory.

这篇关于是什么`DeploymentItem`属性是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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