我試圖用方法調用實現單元測試斷言。 (MustHaveHappened)FakeItEasy失敗斷言與隨機<ignored>參數(並在通話中有匹配)
我用下面的代碼:
[Fact]
public void Should_set_setting_and_map_new_value_for_non_existing_setting()
{
//Arrange
var userSetting = new SettingDetailsBuilder().Build();
var respository = A.Fake<ISettingsRepository>();
A.CallTo(() => respository.GetUserSetting(0, 0, null)).WithAnyArguments().Returns(userSetting);
var dataretriever = new SettingsDataRetriever(respository);
//Act
var newUserSetting = dataretriever.SetUserSetting("variableName", "SomeOtherValue", 1, 1, "FST");
//Assert
A.CallTo(() => respository.GetUserSetting(1, 1, "variableName")).MustHaveHappened();
}
,但我得到隨機失敗的測試,其中一些參數被提及爲「忽略」。然而,這個斷言與確切的參數有關。
錯誤:
Assertion failed for the following call:
AlfaProNext.Repositories.Settings.ISettingsRepository.GetUserSetting(1, <Ignored>, <Ignored>)
Expected to find it at least once but found it #0 times among the calls:
1: AlfaProNext.Repositories.Settings.ISettingsRepository.Exists(varName: "variableName")
2: AlfaProNext.Repositories.Settings.ISettingsRepository.GetUserSetting(
userId: 1,
profileId: 1,
variableName: "variableName")
有誰知道這是爲什麼隨機發生?
我看你還開FakeItEasy問題[562](HTTPS:/ /github.com/FakeItEasy/FakeItEasy/issues/562)與這個問題。我在那裏迴應了一些想法。 –