Difference between Fact and Theory? - xUnit.net

Solution 1:

Assuming that your [AutoMoqData] attribute looks something like this:

public class AutoMoqDataAttribute : AutoDataAttribute
{
    internal AutoMoqDataAttribute()
        : base(new Fixture().Customize(new AutoMoqCustomization()))
    {
    }
}

Then, yes, those two tests are equivalent.

Both [Fact] and [Theory] attributes are defined by xUnit.net.

The [Fact] attribute is used by the xUnit.net test runner to identify a 'normal' unit test: a test method that takes no method arguments.

The [Theory] attribute, on the other, expects one or more DataAttribute instances to supply the values for a Parameterized Test's method arguments.

xUnit.net itself supplies various attributes that derive from DataAttribute: [InlineData], [ClassData], [PropertyData].

AutoFixture hooks into this extensibility point of xUnit.net by supplying the [AutoData] attribute. It can be used to make tests more declarative.