Here’s the method I want to test
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);
}
}
I don’t know how I would test this, I’ve been researching it all day and try various things but cannot get it to work.
I was thinking of including some code such as
#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
I think I just need to see an example and I would know.
I would advise learning about Unit Testing. Read this article on MSDN and search on Google for how to write unit tests. They are a great way to test individual units of code and so should be ideal for your situation.
I would also advise separating out UI-related code, such as calls to
MessageBox, other UI elements andConsole; from the code you wish to test. This will make it much easier to test the logic and execution of your code.