本文介绍了NUnit中的自定义过滤器可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以定义一个自定义过滤器,以便NUnit只运行特定的测试?我有许多用自定义属性BugId标记的Nunit测试。是否有可能编写一个过滤器,以便我可以传入一个数字,只运行具有该属性和数字的测试?如果是这样,显示模型或实际的代码。

解决方案

从NUnit 2.4.6开始,NUnit属性不是密封的,子类是被认为是他们的基础班。因此:
$ b $ pre $ public class BugId:TestAttribute
{
public BugId(int bugNumber):base(测试Bug#+ bugNumber){}
}

[BugId(1)]
public void Test(){}



$ b

可以在命令行中调用:

nunit-console / include = 测试Bug#1

Is it possible to define a custom filter so that NUnit will only run specific tests? I have many of my Nunit tests marked with a custom attribute "BugId". Is it possible to write a filter so that I can pass in a number and only run the tests with that attribute and number? If so show mockup or real code.

解决方案

Starting with NUnit 2.4.6, the NUnit attributes are not sealed and subclasses will be recognized as their base classes. Thus:

public class BugId : TestAttribute
{
    public BugId(int bugNumber) : base("Test for Bug #" + bugNumber) { }
}

[BugId(1)]
public void Test() {}

can be called on the command line like this:

nunit-console /include="Test for Bug #1"

这篇关于NUnit中的自定义过滤器可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 05:38