XUnit Assertion for checking equality of objects

后端 未结 5 862
小蘑菇
小蘑菇 2021-02-03 19:11

I am using XUnit framework to test my C# code.

Is there any assert method available in this framework which does the object comparison? My intention is to check for equa

5条回答
  •  孤城傲影
    2021-02-03 19:45

    I had similar issue, but then luckily I am already using

    using Newtonsoft.Json;
    

    So I just had to serialize it to json object then compare as string.

    var obj1Str = JsonConvert.SerializeObject(obj1);
    var obj2Str = JsonConvert.SerializeObject(obj2);
    Assert.Equal(obj1Str, obj2Str );
    

提交回复
热议问题