TestPropertyAttribute, classe

Mise à jour : novembre 2007

Établit une propriété spécifique de test sur une méthode. Cette classe ne peut pas être héritée.

Espace de noms :  Microsoft.VisualStudio.TestTools.UnitTesting
Assembly :  Microsoft.VisualStudio.SmartDevice.UnitTestFramework (dans Microsoft.VisualStudio.SmartDevice.UnitTestFramework.dll)

Syntaxe

<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

Notes

To see a property, first rebuild the project and then highlight the test in the Test List Editor or the Test View window. La propriété est affichable dans le volet Propriétés une fois le projet régénéré.

Cet attribut peut être spécifié sur une méthode de test. Il peut y avoir plusieurs instances de cet attribut pour spécifier plusieurs éléments.

Pour plus d'informations sur l'utilisation d'attributs, consultez Extension des métadonnées à l'aide des attributs.

Exemples

L'exemple suivant montre comment accéder aux propriétés TestProperty à partir de la méthode MyTestMethod().

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);
         }
      }
   }
}

Hiérarchie d'héritage

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

Sécurité des threads

Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi

Référence

Membres TestPropertyAttribute

Microsoft.VisualStudio.TestTools.UnitTesting, espace de noms

MethodInfo