有条件地忽略 nunit 测试用例 [英] Conditionally ignore nunit testcase

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

问题描述

W.r.t.尼特;是否有一种机制可以有条件地忽略特定的测试用例?

W.r.t. Nunit; Is there a mechanism to conditionally ignore a specific test case?

内容如下:

[TestCase(1,2)]
[TestCase(3,4, Ignore=true, IgnoreReason="Doesn't meet conditionA", Condition=IsConditionA())]
public voidTestA(int a, int b)

那么有没有这样的机制,或者唯一的方法是为每个案例创建单独的测试并在测试主体中执行 Assert.Ignore?

So is there any such mechanism or the only way to do so is to create separate test for each case and do Assert.Ignore in the test body?

推荐答案

您可以在测试正文中添加以下内容:

You could add the following to the body of the test:

if (a==3 && b == 4 && !IsConditionA()) { Assert.Ignore() }

对于您想要忽略的每个测试用例,您都必须这样做.在这种情况下,您不会复制测试体,但您会为每个被忽略的测试用例添加它.

This you would have to do for every testcase you would want to ignore. You would not replicate the testbody in this case, but you would add to it for every ignored testcase.

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

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