TestPropertyAttribute 클래스
업데이트: 2007년 11월
메서드에 대한 테스트 전용 속성을 설정합니다. 이 클래스는 상속될 수 없습니다.
네임스페이스: Microsoft.VisualStudio.TestTools.UnitTesting
어셈블리: Microsoft.VisualStudio.SmartDevice.UnitTestFramework(Microsoft.VisualStudio.SmartDevice.UnitTestFramework.dll)
구문
<AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple := True)> _
Public NotInheritable Class TestPropertyAttribute _
Inherits Attribute
Dim instance As TestPropertyAttribute
[AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = true)]
public sealed class TestPropertyAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method, AllowMultiple = true)]
public ref class TestPropertyAttribute sealed : public Attribute
public final class TestPropertyAttribute extends Attribute
설명
속성을 보려면 먼저 프로젝트를 다시 빌드한 다음 테스트 목록 편집기나 테스트 뷰 창에서 테스트를 강조 표시합니다. 속성은 프로젝트를 다시 빌드한 후에 속성 창에서 볼 수 있습니다.
이 특성은 테스트 메서드에 지정할 수 있습니다. 이 특성의 여러 인스턴스에서 여러 항목을 지정할 수 있습니다.
특성을 사용하는 방법에 대한 자세한 내용은 특성을 사용하여 메타데이터 확장을 참조하십시오.
예제
다음은 MyTestMethod() 메서드 내에서 TestProperty 속성에 액세스하는 방법을 보여 주는 예제입니다.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows.Forms;
using System.Reflection;
namespace TestProperty
{
[TestClass]
public class TestPropertyTest
{
[TestMethod()]
[TestProperty("MyProperty1", "Big")]
[TestProperty("MyProperty2", "Small")]
public void MyTestMethod()
{
// Get the current type
Type t = GetType();
MethodInfo mi = t.GetMethod("MyTestMethod");
Type MyType = typeof(TestPropertyAttribute);
object[] attributes = mi.GetCustomAttributes(MyType, false);
for (int i = 0; i < attributes.Length; i++)
{
string name = ((TestPropertyAttribute)attributes[i]).Name;
string val = ((TestPropertyAttribute)attributes[i]).Value;
string mystring = string.Format("Property Name: {0}, Value: {1}", name, val);
MessageBox.Show(mystring);
}
}
}
}
상속 계층 구조
System.Object
System.Attribute
Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute
스레드로부터의 안전성
이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.