You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are several unit tests in the UnitTests project that check whether exceptions are thrown when they should be. This is done in two different ways:
By placing an [ExpectedException(typeof(TException))] custom attribute on the test method, or
by wrapping a method call or short code block with Assert.Throws<TException>(() => …);.
Using [ExpectedException] is problematic for at least two reasons:
It is too coarse-grained. It doesn't matter which part of a test method throws. However, speaking in terms of Arrange-Act-Assert, only the Act part of a test method should be tested for exceptions.
Suggestion: For these two reasons (and, to a minor degree, for consistency's sake) all test methods using [ExpectedException] should be converted to Assert.Throws.
The text was updated successfully, but these errors were encountered:
stakx
changed the title
Unit tests: Replace [ExpectedException] with Assert.Throws
Unit tests: Replace [ExpectedException] with Assert.ThrowsNov 13, 2016
There are several unit tests in the
UnitTests
project that check whether exceptions are thrown when they should be. This is done in two different ways:[ExpectedException(typeof(TException))]
custom attribute on the test method, orAssert.Throws<TException>(() => …);
.Using
[ExpectedException]
is problematic for at least two reasons:Suggestion: For these two reasons (and, to a minor degree, for consistency's sake) all test methods using
[ExpectedException]
should be converted toAssert.Throws
.The text was updated successfully, but these errors were encountered: