问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/1279175/how-do-i-ignore-a-test-conditionally-in-mbunit