第一个问题问的是:为什么我需要写这个方法?这年代什么给我做吗?
Give the method a more human-friendly name.
From what I can see, the method takes in an integer, a string and a hashtable. The method is then expected to return a dataset containing a solitary table with 3 columns,
- the first row contains values like {"My Column {ColumnNo}"..}
- the second row of which contains the [ intParam.ToString(), stringParam, hashtable["testKey"] ]
Testing this method should be trivial,
Test#1:
- Arrange : Create known inputs (an int I , string S, a hashtable with some "testData"=> Y)
- Act : Call the method and obtain the resulting dataset
- Assert : Query the dataset to see if it has the single table with 2 records. Inspect the contents of the records of the table to see if they contain the header row and the row with [I, S, Y].
Test#2:
Similar to above test, except that you pass in null for the hashtable parameter.
That s all I could see based on the snippet you posted.
HTH
<强> < /强>更新:无法确定你的意思在这里“处理哈希表”或“散列表的代码编写测试夹具”?哈希表是一个参数函数. .所以我认为测试会是这样(原谅坏命名和缺乏常数……t能说出他们的名字,除非我知道这个函数是用于现实生活中)
[Test]
public void Test_NeedsABetterName()
{
int intVal = 101; string stringVal = "MyString"; string expectedHashValue = "expectedValue";
Hashtable ht = new Hashtable();
ht.Add("testKey", expectedHashValue);
Dataset ds = MySampleMethod(intVal, stringVal, ht);
Assert.AreEqual(1, ds.Tables.Count);
Assert.AreEqual(2, ds.Tables[0].Rows.Count);
// check header Row1.. similar to Row2 as shown below
DataRow row2 = ds.Tables[0].Rows[1];
Assert.AreEqual(intVal.ToString(), row2["Column1"]);
Assert.AreEqual(stringVal, row2["Column2"]);
Assert.AreEqual(expectedHashValue, row2["Column3"])
}
我建议得到一本好书像务实的单元测试与NUnit c#或者从列表中< a href = " https://stackoverflow.com/questions/31837/best-books-about-tdd " > < / >速度你这里。