Traits

Organizing Tests With xUnit Traits

Once you start to have a larger number of tests it can be important to be able to break them down into different categories or groupings. From a functionality perspective this allows you to only run a subset of tests. They can also help to provide clarity or insight to your test code, by replacing comments or bloated test names with code based cues to preconditions or domain of the tests.

[Fact]
[Trait("Category", "Fibo")]
public void FiboIncludes13()
{
    var calc = new Calculator();
    Assert.Contains(13, calc.FiboNumbers);
}

[Fact]
[Trait("Category", "Fibo")]
public void FiboDoesNotIncludes4()
{
    var calc = new Calculator();
    Assert.DoesNotContain(4, calc.FiboNumbers);
}

Last updated