這是我想測試如何測試方法(白盒測試)
private static void selectTop20Tags(Dictionary<string, int> list)
{
//Outputs the top 20 most common hashtags in descending order
foreach (KeyValuePair<string, int> pair in list.OrderByDescending(key => key.Value).Take(20))
{
Console.WriteLine("{0}, {1}", pair.Key, pair.Value);
}
}
我不知道我怎麼會測試這個方法,我整天都在研究它,並嘗試不同的東西但不能讓它工作。
我想包括一些代碼,如
#if TEST
if ((length of list don't know how you would do it) <= 20)
{
StreamWriter log2;
// appends file
log2 = File.AppendText("logOfTests.txt");
// Writes to the file
log2.WriteLine("PASS");
log2.WriteLine();
// Closes the stream
log2.Close();
}
#endif
我想我只需要看到一個例子,我會知道的。
你不趕的NRE。你阻止它。 – 2012-01-18 17:51:31
你的方法本身很難測試,因爲它使用'Console'。你可以通過一個'TextWriter'來代替,也許有一個使用'Console.Out'的重載? – 2012-01-18 17:53:14
@Anony Pegram O.k也不確定是否有異常處理。 – Elliot678 2012-01-18 17:55:25