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) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。