Value of Step-by-Step Asserts in Unit Tests

Posted by Eric J. on Stack Overflow See other posts from Stack Overflow or by Eric J.
Published on 2010-06-01T00:04:15Z Indexed on 2010/06/01 0:13 UTC
Read the original article Hit count: 141

Filed under:

When writing unit tests, there are cases where one can create an Assert for each condition that could fail or an Assert that would catch all such conditions. C# Example:

Dictionary<string, string> dict = LoadDictionary();
// Optional Asserts:
Assert.IsNotNull(dict);
Assert.IsTrue(dict.Count > 0);
Assert.IsTrue(dict.ContainsKey("ExpectedKey"));
// Condition actually interested in testing:
Assert.IsTrue(dict["ExpectedKey"] == "ExpectedValue");

Is there value to a large, multi-person project in this kind of situation to add the "Optional Asserts"? There's more work involved (if you have lots of unit tests) but it will be more immediately clear where the problem lies.

I'm using VS 2010 and the integrated testing tools but intend the question to be generic.

© Stack Overflow or respective owner

Related posts about unit-testing