This attribute is used to test whether an expected exception is thrown. The test method will pass if the expected exception is thrown. The test will fail if the thrown exception inherits from the expected exception.
If a test has both an ExpectedException attribute and an Assert statement, either one can cause the test to fail. To determine whether the attribute or the statement caused the test to fail, double-click the test result to open the Results Details page for the test. For more information about test results, see Test Results Reported.
This attribute can be specified on a method. There can be only one instance of this attribute on a method.
For more information about how to use attributes, see Extending Metadata Using Attributes.