Value of Step-by-Step Asserts in Unit Tests
- by Eric J.
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.