Share via


Classe TestPropertyAttribute

Estabelece uma propriedade específica de teste em um método.Esta classe não pode ser herdada.

Namespace:  Microsoft.VisualStudio.TestTools.UnitTesting
Assembly:  Microsoft.VisualStudio.SmartDevice.UnitTestFramework (em Microsoft.VisualStudio.SmartDevice.UnitTestFramework.dll)

Sintaxe

<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

Comentários

Para ver uma propriedade, primeiro recompilar o projeto e, em seguida, realce o teste no Editor de Lista de Testes or the Modo de Teste janela.A propriedade é visível no Propriedades painel depois que o projeto é reconstruído.

Esse atributo pode ser especificado em um método de teste.Pode haver várias instâncias desse atributo para especificar mais de um item.

Para obter mais informações sobre como usar atributos, consulte Estendendo metadados usando atributos.

Exemplos

O exemplo a seguir mostra como acessar as propriedades de TestProperty de dentro do método 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);
         }
      }
   }
}

Hierarquia de herança

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

Acesso thread-safe

Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Consulte também

Referência

Membros TestPropertyAttribute

Namespace Microsoft.VisualStudio.TestTools.UnitTesting

MethodInfo