Ignoring test in MbUnit 3.0.5

Jun 2, 2010 - 1 minute read -

To ignore a test just add the attribute Ignore to the method declaration. What to do if decision about ignoring should be taken during test execution ? There was the Assert.Ignore() method in NUnit and MbUnit 2.0, which causes test ignoring during call.

Unfortunately there is no more such method since MbUnit 3.0. To work around this problem is to throw an appropriate Exception. Here is an example of axuliary test method, which aims to validate length of the field mapping in NHibernate. SQLite has no length for text field, so it should be ignored for such database type. Here is the code:

1
2
3
4
5
6
7
8
protected void AssertPropertyLength(string propertyName, int length)
{
    var driver = ((SessionFactoryImpl)this.Session.SessionFactory).ConnectionProvider.Driver;
    if (driver.GetType().Equals(typeof(SQLite20Driver)))
    {
        throw new SilentTestException(TestOutcome.Ignored, "Test skipped for SQLite");
    }
...