如何在mbUnit中有条件地忽略测试? [英] How do I ignore a test conditionally in mbUnit?

查看:95
本文介绍了如何在mbUnit中有条件地忽略测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TeamCity进行测试和生产的自动化构建.在使用Gallio的过程结束时,TeamCity运行mbUnit 3.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.

运行测试版本时,Gallio应该尝试对测试数据库服务器执行测试.但是,在运行生产版本时,不应运行这些测试,因为TeamCity无法访问生产数据库服务器(即使生产数据库可用,许多测试也会因未发布的代码而失败).

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).

如何标记测试,以便基于boolean值(例如IsDBOnline)在mbUnit中忽略该测试?

推荐答案

创建TestDecoratorAttribute的子类,并重写Initialize()方法以检查IsDBOnline,如果为false则调用Assert.Inconclusive().

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

获得类似效果的另一种方法是在使用Db的测试中添加[Category]属性,然后在生产环境中运行测试时将其过滤掉.

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.

这篇关于如何在mbUnit中有条件地忽略测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆