以编程方式跳过nunit测试 [英] Programmatically skip an nunit test

查看:137
本文介绍了以编程方式跳过nunit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nunit测试是否有办法结束并告诉测试运行者应将其视为跳过/忽略,而不是成功或失败?

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.

很明显,在这种情况下,我可以从测试中返回并允许它成功,但是(a)这似乎是错误的,并且(b)我想知道测试已被跳过。

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 programmatically 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测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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