Author : MD TAREQ HASSAN
Trait Attribute
- Apply Traits attribute to organize tests (Class / Methods level)
- Can be applied to Class or Method level
[Traits("Name", "Value")]
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
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
}
}