XUnit 和 AutoFixture 异常未找到(测试名称)的数据

XUnit and AutoFixture Exception No Data found for (test name)

我有一个非常简单的测试,如下所示。 我尝试使用 AutoDataAttribute + AutoMoqCustomization.

冻结我的两个依赖项
class AutoMoqDataAttribute : AutoDataAttribute
{
    public AutoMoqDataAttribute()
        : base(new Fixture().Customize(new AutoMoqCustomization()))
    { }
}

public class PrBatchEndorseBrokerTest
{
    [Theory, AutoMoqData]
    public void Process_ValidContext_CallsK2Workflows(
        [Frozen]Mock<IK2Datasource> k2,
        [Frozen]Mock<IAppConfiguration> config,
        PrBatchEndorseBroker sut)
    {
        // Arrange
        var data = new Dictionary<string, object>
        {
            ["Workflow"] = @"KLPurchaseRequest\PR",
            ["Activity"] = "Endorser",
            ["ViewFormURL"] = "/Form/KLPurchaseRequestApproval.Form",
            ["PositiveOutcome"] = "Endorse",
            ["NegativeOutcome"] = "Reject"
        };

        // Act
        sut.Process();

        // Assert
        k2.Verify(x =>
            x.StartInstance(It.IsAny<string>(),
                            It.Is<Dictionary<string, object>>(d =>
                                data.Keys.All(k => d[k] == data[k])))
            , Times.Once());
    }
}

由于某些原因,当我 运行 这个测试时,出现以下错误:

System.InvalidOperationException: No data found for BlackBox.Stakhanov.Broker.Test.PrBatchEndorseBrokerTest.Process_ValidContext_CallsK2Workflows

我尝试了很多东西,但我无法让它工作!我想我遗漏了一些大的而且可能很明显的东西!

我正在使用的软件包:

<package id="AutoFixture" version="3.47.8" targetFramework="net452" />
<package id="AutoFixture.AutoMoq" version="3.47.8" targetFramework="net452" />
<package id="AutoFixture.Xunit" version="3.47.8" targetFramework="net461" />
<package id="Castle.Core" version="3.3.3" targetFramework="net461" />
<package id="Moq" version="4.5.10" targetFramework="net461" />
<package id="xunit" version="2.1.0" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
<package id="xunit.assert" version="2.1.0" targetFramework="net461" />
<package id="xunit.core" version="2.1.0" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net461" />
<package id="xunit.extensions" version="1.9.0.1566" targetFramework="net461" />

使用xUnit.net2时,应该使用AutoFixture.Xunit2, not AutoFixture.Xunit

您会在软件包列表中注意到您有 xunit.extensions 版本 1.9.0.1566,它与 xUnit.net 2.

不兼容