Assert.AreEqual failing in unit test

后端 未结 10 1359
挽巷
挽巷 2021-01-18 14:54

I have the following unit test:

string MtrlCode = \"0\";
Assessment target = new Assessment(MtrlCode);

List EdgeCaseSymbolCodes = new List<         


        
相关标签:
10条回答
  • 2021-01-18 15:30

    If you want to compare to List you can create a void function with that code Snippet.

    Assert.AreEqual(response.Count, acceptedResponse.Count,"Diferent list length");
                for (int i = 0; i < acceptedResponse.Count; i++)
                {
                    Assert.AreEqual(response[i],acceptedResponse[i]);
                }
    
    0 讨论(0)
  • 2021-01-18 15:31

    The Assert fails because it verifies whether the two lists are in fact the same instance. They are not; it's two different list instances. You will need to write code to verify that the two lists contains the same set of items.

    0 讨论(0)
  • 2021-01-18 15:35

    I am also faced(ing) the same problem. As a work around you can check the count of the list, and do a for each and check for contains.

    0 讨论(0)
  • 2021-01-18 15:39

    Use CollectionAssert.AreEqual().

    0 讨论(0)
提交回复
热议问题