7
我有一個非常簡單的測試,如下所示。 我嘗試使用AutoDataAttribute
+ AutoMoqCustomization
來凍結我的兩個依賴關係。XUnit和AutoFixture異常未找到(測試名稱)數據
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" />
您是否嘗試過做''AutoMoqDataAttribute' public'? –
同樣的結果。我試圖刪除PrBatchEndorseBroker,將其添加回來..始終是相同的錯誤 – Seb
您能否列出_exactly_您正在使用哪個NuGet包?您可以通過NuGet程序包管理器控制檯中的「Get-Package」輕鬆獲取列表。 –