How to compare Lists in Unit Testing

后端 未结 7 1543
闹比i
闹比i 2020-11-30 00:24

How can this test fail?

[TestMethod]
public void Get_Code()
{
    var expected = new List();
    expected.A         


        
7条回答
  •  既然无缘
    2020-11-30 00:57

    List adminDetailsExpected = new List()
    {
    new AdminUser  {firstName = "test1" , lastName = "test1" , userId = 
    "001test1"  },
    new AdminUser {firstName = "test2" , lastName = "test2" , userId = 
    "002test2"   }
    };
    

    //Act

    List adminDetailsActual = RetrieveAdmin(); // your retrieve logic goes here
    

    //Assert

    Assert.AreEqual(adminDetailsExpected.Count, adminDetailsActual.Count);  //Test succeeds if the count matches else fails. This count can be used as a work around to test
    

提交回复
热议问题