我有一个测试验证方法的集合输出。测试的这种变化通过:
[TestMethod, TestCategory("BVT")]
public void TheStatusesAreReturned()
{
var expectedUnprocessedStatuses = new List<FileUploadStatus>
{
FileUploadStatus.InProcess,
FileUploadStatus.Pending,
};
Sut.GetUnprocessedStatuses()
.Should()
.BeEquivalentTo(expectedUnprocessedStatuses);
}
测试的这种变化失败,错误“预期项目[0]为InProcess,但发现待定”:
[TestMethod, TestCategory("BVT")]
public void TheStatusesAreReturned2()
{
var expectedUnprocessedStatuses = new List<FileUploadStatus>
{
FileUploadStatus.InProcess,
FileUploadStatus.Pending,
};
Sut.GetUnprocessedStatuses()
.ShouldBeEquivalentTo(expectedUnprocessedStatuses);
}
显然,ShouldBeEquivalentTo
关注收集项目顺序,而BeEquivalentTo
则不关心。为什么两种方法之间的等效概念不同?
答案 0 :(得分:11)
你是对的。应该()。BeEquivalentTo()使用单个项目Equals()实现来验证等效性,并且从版本1开始就已经存在.FA 2.0中引入的较新的ShouldBeEquivalentTo()正在进行深入的结构比较,并报告任何差异。对于2.1,我将更改行为更像是默认的集合等效性