xUnit allows our unit test to use parameters, which allows us to test our code for multiple scenarios without needing to write multiple methods with same content.

Let’s look at example from previous lesson

Here we test if 3 + 9 equals 12.

But what if we wanted to test our Add method for multiple scenarios?


We could use InlineData Attribute.

InlineData Attribute allows us to run our test with input parameters, and passes those parameters to test method using params object[] data.

We are not done yet.

Compiler is not happy and we are getting error : Fact methods cannot have parameters.

Simple solution is to replace Fact Attribute with Theory Attribute

Now, when we run our unit test we can see that same test method ran 3 times an all test have passed  đŸ™‚

Also note that we can also see input parameters!