用于测试ArrayList对象的NUnit测试用例

时间:2009-08-12 13:04:47

标签: nunit

我有一个方法可以检索DataTable并迭代每个DataRow并存储每一行 在ArrayList中。迭代结束后,它返回ArrayList。如何编写测试用例来测试ArrayList?

示例:

ArrayList => 0({1,personName1,Designation});

ArrayList => 1({2,personName2,Designation});

ArrayList => 2({3,personName3,Designation});

提前致谢。

1 个答案:

答案 0 :(得分:1)

可能类似以下内容:

[Test]
public void RetrieveDataTableAndArrayList()
{
    // set up dependencies here
    // i.e. maybe a mocked DataSet which would return your DataTable?

    // an instance of the class under test
    var sut = new SystemUnderTest(dataSet); 

     // the method that you are testing
    ArrayList result = sut.RetrieveDataTable();

    // verification of results
    DataRow row1 = (DataRow)result[0];
    Assert.AreEqual(1, row1.Field<int>(0));
    Assert.AreEqual("personName1", row1.Field<string>(1));
    Assert.AreEqual("Designation", row1.Field<string>(2));
    // ... and so on
}