NUnit Ignore Attribute
Friday 24 January 2003
NUnit has a nice feature for specifying that test fixtures or individual tests should be ignored: the Ignore attribute. For example:
[Test]
[Ignore("code for handling different cultures not implemented")]
public void testXmlRpcDouble_ForeignCulture()
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
XmlDocument xdoc;
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-BE");
XmlRpcDouble xsd = new XmlRpcDouble(543.21);
Console.WriteLine(xsd.ToString());
xdoc = Utils.Serialize(
"SerializeTest.testXmlRpcDouble_ForeignCulture",
new XmlRpcDouble(543.21),
Encoding.UTF8, MappingAction.Ignore);
}
catch(Exception)
{
throw;
}
finally
{
Thread.CurrentThread.CurrentCulture = currentCulture;
}
Type parsedType, parsedArrayType;
object obj = Utils.Parse(xdoc, null, MappingAction.Error,
out parsedType, out parsedArrayType);
Assertion.AssertEquals(543.21, obj);
}
Its very convenient when you think of something that needs testing but which cannot be tested yet for some reason. A bit like making a note in your project todo list except in this case you won't be able to ignore or lose the note: each time you run your tests in the NUnit gui the ignored tests and the overall progress/success bar are marked in yellow instead of the usual green for sucess. This is much better than commenting out code in a test harness where it is likely to be forgotten.
Posted by
at 08:54 AM.
Permalink.
Copyright © Charles Cook.
Valid XHTML 1.0