问题描述
有没有办法为NUnit测试结束,并告诉测试运行,它应该考虑跳过/忽略不计,而不是成功还是失败?
我的动机,这是我有几个测试,不要在某些情况下适用,但不能确定,直到测试(或者夹具)开始运行。
显然,在这种情况下,我可以从测试返回并使其成功,但(一)这似乎是错误的和(b)我想知道测试已经跳过了。
我知道的[忽略]属性的,但是这是编译项。我正在寻找一个运行时,程序化等同。是这样的:
如果(testNotApplicable)
抛出新NUnit.Framework.IgnoreTest(不适用);
或者是编程跳过测试只是错了吗?如果是的话,我应该怎么做?
Assert.Ignore();
特别是你问的是什么,虽然也有:
Assert.Inconclusive();
Is there a way for an nunit test to end and tell the test runner that it should be considered skipped/ignored, rather than succeeded or failed?
My motivation for this is that I have a few tests that don't apply in certain circumstances, but this can't be determined until the test (or maybe the fixture) starts running.
Obviously in these circumstances I could just return from the test and allow it to succeed, but (a) this seems wrong and (b) I'd like to know that tests have been skipped.
I am aware of the [Ignore] attribute, but this is compiled-in. I'm looking for a run-time, programatic equivalent. Something like:
if (testNotApplicable)
throw new NUnit.Framework.IgnoreTest("Not applicable");
Or is programatically skipping a test just wrong? If so, what should I be doing?
Assert.Ignore();
is specifically what you're asking for, though there is also:
Assert.Inconclusive();
这篇关于编程方式跳过NUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!