moodmosaic

Parameterized Tests with xUnit.net

Update (2026-11-17): Flickr no longer serves the photos linked here, so the links and images are dead. The originals are gone unless a copy turns up.

Sometimes you have several unit-tests implementing the same test algorithm. These tests are exactly the same, having only different data.

With Pex you can cover your code with parameterized tests (there is also a tutorial here). However, you can also do it with xUnit.net.

Add a reference to xunit.extensions.dll and decorate any parameterized test methods with [Theory] attribute (instead of [Fact]). Then decorate it with [InlineData]attribute if the data is coming from inlined values.

There are also additional attributes (each one taking parameters so xUnit.net can successfully locate the test data):

Choose the one that suits your needs.