Conditionally ignore nunit testcase

会有一股神秘感。 提交于 2020-08-24 07:58:28

问题


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

Something in the lines of :

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

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?


回答1:


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.




回答2:


I think it helps test readability to minimize the conditional logic inside the test body. But you can definitely generate the tests cases dynamically using the testcasesource attribute on the test and in a separate method dynamically generate a list of test cases to run using the nunit testcasedata object.

So only the tests that you need to/ are valid to execute are run but you still have a chance to log etc the cases.

http://www.nunit.org/index.php?p=testCaseSource&r=2.6.4



来源:https://stackoverflow.com/questions/29014835/conditionally-ignore-nunit-testcase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!