Replacing [ExpectedException] in WinRT unit test library

Recently I needed to write an unit test for my Windows Store application, that would check if a code snippet caused an expected exception. Usually this is done in the following manner:

However, the Unit Test Library for WinRT lacks the ExpectedException attribute.

Luckily, it was replaced by a far more convenient and useful method  Assert.ThrowsException :

You need to provide the type of expected exception as the type parameter of this method and then a lambda expression (or   Action  instance), that contains the code that should throw the exception.

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 class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*