[英]How do I write a unit test for a void method and create a mock dataset and a datarow(Both dataset and datarow are strongly typed)?
I have a method whose return type is void.我有一个返回类型为 void 的方法。 This method has two parameters, a strongly typed datarow and dataset.该方法有两个参数,强类型数据行和数据集。
private void Check(Dataset testDB, DataRow testRow)
{
if(testRow.Amount>10)
{
decimal rate = testRow.Rate;
if(rate >= 100)
{
AddData(testDB,testRow,"some text");
}
}
}
private void AddData(Dataset testDB, DataRow testRow, string notes)
{
Dataset.StudentRow newRow=testDB.Students.NewStudentRow();
.
.
.
testDB.Students.AddStudentRow(newRow);
}
You will not do any mocking.你不会做任何 mocking。 You will use real DataSet and DataRow and assert that data are correctly defined in data set after calling the method.您将使用真实的 DataSet 和 DataRow,并在调用该方法后断言数据在数据集中已正确定义。 You generally need several unit tests to cover the method:您通常需要几个单元测试来涵盖该方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.