Author : MD TAREQ HASSAN

Trait Attribute

Using Trait Attribute

public class CustomCategoryTrait
{
    [Fact]
    [Traits("Category", "DataLayer")] 
    public void TestOne()
    {
        // Assert
    }

    [Fact]
    [Traits("Category", "PresentationLayer")] 
    public void TestTwo()
    {
        // Assert
    }    
}

In Test Explorer, you can filter tests by Traits

Trait

Custom Trait Attribute

class CategoryAttribute : TraitAttribute
{
    public CategoryAttribute(string categoryName) : base("Category", categoryName)
    {

    }
}

Using Custom Trait Attribute

public class CustomCategoryTrait
{
    [Fact]
    [SmokeTest]
    [Category("DataLayer")]
    public void TestOne()
    {
        // Assert
    }

    [Fact]
    [SmokeTest]
    [Category("PresentationLayer")]
    public void TestTwo()
    {
        // Assert
    }    
}

Named Custom Trait

class FooTestAttribute : TraitAttribute
{
    public FooTestAttribute() : base("Category", "FooTest")
    {

    }
}

Using Named Custom Trait Attribute

public class CustomCategoryTrait
{
    [Fact]
    [FooTest]
    public void TestOne()
    {
        // Assert
    }

    [Fact]
    [FooTest]
    public void TestTwo()
    {
        // Assert
    }    
}