Parameterized Tests with xUnit.net

February 17, 2011 | Unit Testing | xUnit.net

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 [Theoryattribute (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.