如何在mbUnit中有条件地忽略测试?

编程入门 行业动态 更新时间:2024-10-09 18:25:29
本文介绍了如何在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中有条件地忽略测试?

本文发布于:2023-11-23 00:44:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619509.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中有   条件   测试   如何在   mbUnit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!