Composite xUnit.net Data Attributes
27 July 2012
xUnit.net extensions support data-driven tests called Theories. Such tests are similar to regular xUnit.net tests but instead of being decorated with
[Fact] they are decorated with
Below is a data-driven test with the data coming a Microsoft Excel (.xls) spreadsheet.
Also, a data-driven test with the data coming from a type implementing the IEnumerable<object>.
In the above samples,
[ClassData] are attributes representing a data source for a data-driven test.
Using data from multiple attributes
Below is a data-driven test with the data coming from a type implementing the IEnumerable<object> combined with the data coming from an .xls spreadsheet.
Creating a composite attribute
[ClassExcelData] from the previous example is a composite of two xUnit.net’s data attributes
All we have to do is create a type deriving from
CompositeDataAttribute, passing in its base constructor an array of the data attributes we would like to compose.
The description for the
CompositeDataAttribute algorithm can be found here.
Obtaining the CompositeDataAttribute class
CompositeDataAttribute is currently bundled with AutoFixture extension for xUnit.net. You can use it by installing the AutoFixture.Xunit NuGet package.