2011-05-04 17 views
1

我有一個返回類型爲void的方法。該方法有兩個參數,一個強類型的數據行和數據集。如何爲void方法編寫單元測試並創建模擬數據集和數據行(數據集和數據行都是強類型的)?

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); 
} 
+2

我們在這裏有什麼語言?代碼在c#中 – bmargulies 2011-05-04 21:02:29

+0

代碼是在c# – Talk2me 2011-05-04 21:08:39

回答

1

你不會做任何嘲弄。您將使用真實的DataSet和DataRow,並在調用該方法後聲明數據已在數據集中正確定義。一般需要幾個單元測試,以覆蓋方法:

  • 與具有金額11但率99
  • 與行單元測試具有金額11行和評論100具有行金額10
  • 單元測試單元測試
相關問題