tags:

views:

203

answers:

1

I'm using TeamCity to do automated builds of test and production. TeamCity runs our mbUnit 3.1 tests at the end of the process with Gallio.

When running the test build, Gallio should try to execute tests against the test database server. However, when running a production build, these tests should not be run because TeamCity can't access the production database server (and if even if the production database was available, many tests would fail with unreleased code).

How can I mark a test so that it gets ignored in mbUnit based on a boolean value such as IsDBOnline?

+3  A: 

Create a subclass of TestDecoratorAttribute and override the Initialize() method to check IsDBOnline and call Assert.Inconclusive() if false.

Another way to achieve a similar effect is to add a [Category] attribute to the tests that use the Db and then filter them out when running the tests on production.

Jeff Brown
Actually, instead of calling Assert.Inconclusive you might find it better to throw a special exception that sets the test outcome:throw new SilentTestException(TestOutcome.Ignored, "Some message");
Jeff Brown
And now that I think about it, I did create a method for this purpose too! Assert.TerminateSilently(TestOutcome.Ignored, "Some message");
Jeff Brown
I subclassed TestDecoratorAttribute like you suggested, overrode the Initilize method and then called Assert.TerminateSilently when the database is offline, and base.Initialize when it was. This worked great! Thanks!
ranomore