How do I ignore a test conditionally in mbUnit?

2019-07-11 20:39发布

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?

标签: mbunit gallio
1条回答
做个烂人
2楼-- · 2019-07-11 21:27

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.

查看更多
登录 后发表回答