moodmosaic (Nikos Baxevanis)
Blog - About - Open Source - Bookmarks - Tags

Combining Data Theories in AutoFixture.Xunit extension

Thursday, 25 August 2011 supports parameterized tests via data theories which are types deriving from the Xunit.Extensions.DataAttribute type. Some popular attributes include:

InlineDataAttribute, PropertyDataAttribute and ClassDataAttribute.

AutoFixture.Xunit extension includes a very useful type, for providing auto-data theories, called AutoMoqDataAttribute

Imagine a Scenario where we have a unit test method with 3 parameters. We want the first parameters to be supplied by InlineData and the rest by AutoFixture using AutoMoqData.

[InlineAutoData("foo", "bar")]
public void Test(string s1, string s2, MyClass myClass)

This is now possible using the InlineAutoDataAttribute type which is now on the trunk and will be available on next public release (after version 2.1). It provides a data source for a data theory, with the data coming from inline values combined with auto-generated data specimens generated by AutoFixture.

InlineAutoDataAttribute derives from CompositeDataAttribute, an implementation of DataAttribute that composes other DataAttribute instances.

Here is how it works:

While this feature comes with AutoFixture.Xunit extension, the CompositeDataAttribute class depends only on the xunit.extensions assembly.

You may compile the code from the latest trunk version, alternatively the latest build (including strong names) can be downloaded from here.


This post has been filed under #autofixture


Have feedback on this page? Let @nikosbaxevanis know on twitter. Need help or found a bug? Contact me.

© 2011-2018 Nikos Baxevanis. All written content on this site is provided under a Creative Commons ShareAlike license. All code is provided under a MIT license unless otherwise stated.