다음을 통해 공유


DeploymentItemAttribute 클래스

테스트별 배포를 위한 파일이나 디렉터리와 같은 배포 항목을 지정하는 데 사용됩니다. 이 클래스는 상속될 수 없습니다.

상속 계층 구조

System.Object
  System.Attribute
    Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute

네임스페이스:  Microsoft.VisualStudio.TestTools.UnitTesting
어셈블리:  Microsoft.VisualStudio.QualityTools.UnitTestFramework(Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll)

구문

‘선언
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Method, AllowMultiple := True)> _
Public NotInheritable Class DeploymentItemAttribute _
    Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true)]
public sealed class DeploymentItemAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Method, AllowMultiple = true)]
public ref class DeploymentItemAttribute sealed : public Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true)>]
type DeploymentItemAttribute =  
    class
        inherit Attribute
    end
public final class DeploymentItemAttribute extends Attribute

DeploymentItemAttribute 형식에서는 다음과 같은 멤버를 노출합니다.

생성자

  이름 설명
Public 메서드 DeploymentItemAttribute(String) DeploymentItemAttribute 클래스의 새 인스턴스를 초기화합니다.이 생성자를 사용하여 만든 개체는 배포 항목이나 디렉터리의 경로를 사용하여 초기화됩니다.
Public 메서드 DeploymentItemAttribute(String, String) DeploymentItemAttribute 클래스의 새 인스턴스를 초기화합니다.이 생성자를 사용하여 만든 개체는 배포 항목과 출력 디렉터리의 경로를 사용하여 초기화됩니다.

위쪽

속성

  이름 설명
Public 속성 OutputDirectory 출력 디렉터리에 대한 경로를 나타내는 값을 가져옵니다.
Public 속성 Path 배포 항목의 경로를 나타내는 값을 가져옵니다.
Public 속성 TypeId 파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다. (Attribute에서 상속됨)

위쪽

메서드

  이름 설명
Public 메서드 Equals 인프라입니다. 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다. (Attribute에서 상속됨)
Protected 메서드 Finalize 가비지 수집에서 회수하기 전에 개체에서 리소스를 해제하고 다른 정리 작업을 수행할 수 있게 합니다. (Object에서 상속됨)
Public 메서드 GetHashCode 이 인스턴스에 대한 해시 코드를 반환합니다. (Attribute에서 상속됨)
Public 메서드 GetType 현재 인스턴스의 Type을 가져옵니다. (Object에서 상속됨)
Public 메서드 IsDefaultAttribute 파생 클래스에서 재정의된 경우 이 인스턴스의 값이 파생 클래스의 기본값인지 여부를 나타냅니다. (Attribute에서 상속됨)
Public 메서드 Match 파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다. (Attribute에서 상속됨)
Protected 메서드 MemberwiseClone 현재 Object의 단순 복사본을 만듭니다. (Object에서 상속됨)
Public 메서드 ToString 현재 개체를 나타내는 문자열을 반환합니다. (Object에서 상속됨)

위쪽

명시적 인터페이스 구현

  이름 설명
명시적 인터페이스 구현Private 메서드 _Attribute.GetIDsOfNames 이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다. (Attribute에서 상속됨)
명시적 인터페이스 구현Private 메서드 _Attribute.GetTypeInfo 인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다. (Attribute에서 상속됨)
명시적 인터페이스 구현Private 메서드 _Attribute.GetTypeInfoCount 개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1). (Attribute에서 상속됨)
명시적 인터페이스 구현Private 메서드 _Attribute.Invoke 개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다. (Attribute에서 상속됨)

위쪽

설명

테스트 설정에 따라 Microsoft Visual Studio 2010은 테스트를 만든 폴더 또는 별도의 "배포" 폴더에서 테스트를 실행합니다. 테스트 설정에 대한 자세한 내용은 Visual Studio에서 자동화된 테스트를 실행하기 위한 테스트 설정 만들기를 참조하십시오.

이 단원에서는 Microsoft Visual Studio 2010에서 빌드된 어셈블리가 들어 있는 폴더가 아닌 다른 폴더에서 테스트를 실행하는 경우를 설명합니다.

이러한 방식으로 테스트를 실행할 때 테스트와 테스트 대상 코드 어셈블리 및 배포 항목은 해당 테스트 실행에만 적용되는 고유한 테스트 배포 폴더에 저장됩니다. 이 특성은 실행하기 위해 배포된 테스트에서 사용할 파일이 들어 있는 디렉터리와 파일을 식별합니다. 테스트 엔진은 배포 항목의 복사본을 만들고 기본 디렉터리나 지정된 OutputDirectory에 따른 테스트 배포 디렉터리에 이러한 복사본을 추가합니다.

이 특성은 테스트 메서드나 테스트 클래스에 지정할 수 있습니다. 그러나 이 특성은 파생 클래스에서 상속되지 않습니다.

이 특성의 여러 인스턴스에서 여러 항목을 지정할 수 있습니다. 항목 경로는 절대적이거나 상대적일 수 있습니다. 상대적 경로는 프로젝트 경로에 상대적입니다.

다음은 각기 다른 방식으로 DeploymentItemAttribute를 사용하는 방법을 보여 주는 예제입니다.

  • [DeploymentItem("file1.xml")]   프로젝트 경로에 위치한 file1.xml 이름의 항목을 배포합니다. 이 파일은 배포 루트 디렉터리에 배포됩니다.

  • [DeploymentItem("file2.xml", "DataFiles")]   프로젝트 경로에 위치한 file2.xml 이름의 항목을 배포합니다. 이 파일은 배포 루트 디렉터리의 DataFiles 하위 디렉터리에 배포됩니다.

  • [DeploymentItem("C:\\MyDataFiles\\")]   MyDataFiles 디렉터리에 있는 모든 항목과 디렉터리를 배포합니다. 이 경우 배포 디렉터리 아래에 MyDataFiles 디렉터리가 작성되지 않습니다. MyDataFiles 내의 모든 파일과 디렉터리는 배포 루트 디렉터리에 배포됩니다. 전체 MyDataFiles 디렉터리 구조를 복사하려면 MyDataFiles를 출력 디렉터리로 지정해야 합니다.

  • [DeploymentItem("%myDir%\myFile.txt")]   %myDir%로 확인되는 디렉터리에 myFile.txt 파일이 있으면 이 파일을 배포합니다.

특성을 사용하는 방법에 대한 자세한 내용은 특성을 사용하여 메타데이터 확장을 참조하십시오.

예제

다음 클래스에서는 테스트 메서드에 사용할 파일을 만듭니다.

using System;
using System.IO;

namespace CarMaker
{
    public class Car
    {
        private static string make = "myMake";
        private static string model = "myModel";

        public static void CarInfo()
        {
            using (StreamWriter sw = new StreamWriter("testFile1.txt"))
            {
                sw.WriteLine(make);
                sw.WriteLine(model);
            }
        }
    }
}
Imports System
Imports System.IO

Namespace CarMaker
    Public Class Car

        Private Shared make As String = "myMake"
        Private Shared model As String = "myModel"

        Public Shared Sub CarInfo()
            Dim sw As New StreamWriter("testFile1.txt")
            Try
                sw.WriteLine(make)
                sw.WriteLine(model)
            Finally
                sw.Close()
            End Try
        End Sub
    End Class
End Namespace

다음 테스트 클래스에는 "testFile1.txt"라는 파일을 만드는 데 사용할 Car 클래스를 인스턴스화하기 위한 테스트 메서드가 들어 있습니다. 이 파일은 DeploymentItemAttribute에서 식별한 결과대로 배포됩니다. 그런 다음 테스트 메서드는 테스트 어셈블리와 동일한 디렉터리에 파일이 있는지 여부를 테스트합니다.

using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CarMaker;

namespace DeploymentTest
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod()]
        [DeploymentItem("testFile1.txt")]
        public void ConstructorTest()
        {
            // Create the file to deploy
            Car.CarInfo();
            string file = "testFile1.txt";
            // Check if the created file exists in the deployment directory
            Assert.IsTrue(File.Exists(file), "deployment failed: " + file +
                " did not get deployed");
        }
    }
}
Imports System
Imports System.IO
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports MyVBProject.CarMaker

Namespace DeploymentTest
    <TestClass()> _
    Public Class UnitTest1
        <TestMethod()> _
        <DeploymentItem("testFile1.txt")> _
        Sub ConstructorTest()
            Car.CarInfo()
            Dim file As String = "testFile1.txt"
            Assert.IsTrue(IO.File.Exists(file), "deployment failed: " + file + _
                " did not get deployed")
        End Sub
    End Class
End Namespace

스레드로부터의 안전성

이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

참고 항목

참조

Microsoft.VisualStudio.TestTools.UnitTesting 네임스페이스