Unit testing a function but the function isn't returning anything when I run the unit test.
This is the function
public string FindUniqueWords(Dictionary<string, int> dictionary)
{
string uniqueWord = "";
foreach (KeyValuePair<string, int> pair in dictionary) //loop through the occurenceDictionary
{
uniqueWord += (pair.Key + ", ");
}
uniqueWords.Text = uniqueWord;
return (uniqueWord);
}
And this is the unit test
[TestMethod]
public void CheckUniqueWordsAreFoundTest()
{
string actual, expected;
Form1 frm1 = new Form1();
actual = frm1.FindUniqueWords(unitTestOccurenceDictionary);
expected = "hello, world, i, am, god, of, this";
Assert.AreEqual(expected, actual);
}
And I am sending this dictionary to the function
public class UnitTest1
{
public Dictionary<string, int> unitTestOccurenceDictionary = new Dictionary<string, int>();
public void Add(string key, string value)
{
unitTestOccurenceDictionary.Add("hello", 1);
unitTestOccurenceDictionary.Add("world", 2);
unitTestOccurenceDictionary.Add("I", 1);
unitTestOccurenceDictionary.Add("am", 1);
unitTestOccurenceDictionary.Add("god", 1);
unitTestOccurenceDictionary.Add("of", 1);
unitTestOccurenceDictionary.Add("this", 1);
}
When I run the unit test it fails and shows that actual = <> I am not sure what is causing this but I feel like it's a stupidly simple mistake like a missing reference but there are no errors when I run my code.
Aucun commentaire:
Enregistrer un commentaire