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

发布于 2024-07-30 18:07:29 字数 277 浏览 1 评论 0原文

我正在使用 TeamCity 进行测试和生产的自动化构建。 TeamCity 在流程结束时与 Gallio 一起运行我们的 mbUnit 3.1 测试。

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

层林尽染 2024-08-06 18:07:29

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文