When asserting the content of collections, lists, dictionaries,… in unit tests, don’t do this:

Assert.That(this.result.Contains(this.expectedResult1));
Assert.That(this.result.Contains(this.expectedResult2));

 

Or this:

Assert.AreEqual(this.expectedResult1, this.result[0]);
Assert.AreEqual(this.expectedResult2, this.result[1]);

What if you implemented your method wrong, and the result contains more than two elements? Unless you’re totally not interested in the size of the result, always check if the collection is as big as you expect it to be:

Assert.AreEqual(2, this.expectedResult.Count);
Assert.AreEqual(this.expectedResult1, this.result[0]);
Assert.AreEqual(this.expectedResult2, this.result[1]);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.