OkraFramework / Okra.Core

Okra App Framework - The Okra App Framework is designed to support the development of .Net Windows Store applications, in particular those following the MVVM pattern.
http://okraframework.github.io
Apache License 2.0
10 stars 6 forks source link

When unit testing exceptions, also check exception message #67

Closed Andy-Wilkinson closed 9 years ago

Andy-Wilkinson commented 9 years ago

From the ASP.Net engineering guidelines (https://github.com/aspnet/Home/wiki/Engineering-guidelines#extension-method-patterns)

"In general testing the specific exception message in a unit test is important. This ensures that the exact desired exception is what is being tested rather than a different exception of the same type. In order to verify the exact exception it is important to verify the message.

To make writing unit tests easier it is recommended to compare the error message to the RESX resource. However, comparing against a string literal is also permitted."

var ex = Assert.Throws<InvalidOperationException>(
    () => fruitBasket.GetBananaById(1234));
Assert.Equal(
    Strings.FormatInvalidBananaID(1234),
    ex.Message);