C# 使用Xunit测试多个派生类型的最佳方法是什么?

C# 使用Xunit测试多个派生类型的最佳方法是什么?,c#,unit-testing,xunit,C#,Unit Testing,Xunit,我有一个接口IFoo public interface IFoo { void DoSomeStuff(); } 我有两个派生类型FooImpl1和FooImpl2: public class FooImpl1 : IFoo { public void DoSomeStuff() { //... } } public class FooImpl2 : IFoo { public void DoSomeStuff() {

我有一个接口
IFoo

public interface IFoo
{
    void DoSomeStuff();
}
我有两个派生类型
FooImpl1
FooImpl2

public class FooImpl1 : IFoo
{
    public void DoSomeStuff()
    {
        //...
    }
}

public class FooImpl2 : IFoo
{
    public void DoSomeStuff()
    {
        //Should do EXACTLY the same job as FooImpl1.DoSomeStuff()
    }
}
我有一个测试类,它测试
IFoo
FooImpl1
契约:

    private static IFoo FooFactory()
    {
        return new FooImpl1();
    }

    [Fact]
    public void TestDoSomeStuff()
    {
        IFoo foo = FooFactory();

        //Assertions.
    }

如何重用此测试类来测试
FooImpl1
FooImpl2

IFoo
测试的基类返回适当的实现如何

public abstract class FooTestsBase
{
    protected abstract IFoo GetTestedInstance();

    [Fact]
    public void TestDoSomeStuff()
    {
        var testedInstance = GetTestedInstance();
        // ...
    }
}
现在,所有派生类型只需提供一个实例:

public class FooImpl1Tests : FooTestsBase
{
    protected override IFoo GetTestedInstance()
    {
        return new FooImpl1();
    }
}

您知道如何使用
xUnit2
整形器xunit
实现此功能吗?对于共享事实,我从抽象夹具中得到的测试本身不可运行。