NUnit
|    
* *
    |

Expected Exception (NUnit 2.0)
This is the way to specify that the execution of a test will throw an exception. This attribute takes a parameter which is a Type. The runner will execute the test and if it throws the specific exception, then the test passes. If it throws a different exception the test will fail. This is true even if the thrown exception inherits from the expected exception.

Example:

Language Filter
namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  public class SuccessTests
  {
    [Test]
    [ExpectedException(typeof(InvalidOperationException))]
    public void ExpectAnException()
    { /* ... */ }
  }
}


Copyright © 2002-2004 James W. Newkirk, Alexei A. Vorontsov. All Rights Reserved.
|