How to Compare two objects in unit test?

前端 未结 15 1702
自闭症患者
自闭症患者 2020-11-30 03:15
public class Student
{
    public string Name { get; set; }
    public int ID { get; set; }
}

...

var st1 = new Student
{
    ID =          


        
15条回答
  •  清歌不尽
    2020-11-30 03:36

    You can also use NFluent with the this syntax to deep compare two objects without implementing equality for your objects. NFluent is a library that tries to simplify writing readable test code.

    Check.That(actual).HasFieldsWithSameValues(expected);
    

    This method with fail with an exception containing all the differences instead of failing at the first one. I find this feature to be a plus.

提交回复
热议问题