运行以下测试时,所有断言都会失败。无法弄清楚它们失败的原因,因为实际的实现确实调用了对象。
这是一个已知的错误吗?因为其他一些测试确实成功了。
[Subject("Pst Cleanup")]
public class When_running_Pst_CleanUp
{
Establish context = () =>
{
_folders = A.Fake<IOutlookFolderParameters>();
_processor = A.Fake<IOutlookPstCleaner>();
};
Because of = () => _processor.Cleanup(_folders);
It should_cleanup_the_mail_folder = () => A.CallTo(() => _folders.EmailFolder).MustHaveHappened();
It should_cleanup_tasks_folder = () => A.CallTo(() => _folders.TaskFolder).MustHaveHappened();
It should_cleanup_appointments_folder = () => A.CallTo(() => _folders.AppointmentFolder).MustHaveHappened();
private static IOutlookPstCleaner _processor;
private static IOutlookFolderParameters _folders;
}
以下调用的断言失败:Outlook.Contracts.IOutlookFolderParameters.get_NotificationsFolder()预计至少找到一次,但不会对假对象进行调用。
at FakeItEasy.Core.FakeAsserter.AssertWasCalled(Func
2 callPredicate, String callDescription, Func
2 repeatPredicate,String repeatDescription)在UnitTests.When_running_Pst_CleanUp的FakeItEasy.Configuration.RuleBuilder.MustHaveHappened(重复repeatConstraint)。&lt; .ctor&gt; b__2()in When_running_Pst_CleanUp.cs:第19行
答案 0 :(得分:3)
这是FakeItEasy绝对正确的行为。您需要使用IOutlookPstCleaner
的真实实现来使您的测试成功。始终确保你伪造正确的东西,不要意外伪造你的SUT。
通过对刚刚调用的属性进行测试,您完全没有任何重要的测试。我也可以为IOutlookPstCleaner
编写这个实现,你的测试就会成功:
public class Cleaner : IOutlookPstCleaner
{
public void Cleanup(IOutlookFolderParameters folders)
{
var email = folders.EmailFolder;
var task = folders.TaskFolder;
var appointment = folders.AppointmentFolder;
}
}
如果你发布IOutlookPstCleaner
的实现,我很乐意帮助你找到合适的测试对象。</ p>