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.
The Category attribute provides an alternative to suites for dealing with groups of tests. Either individual test cases or fixtures may be identified as belonging to a particular category. Both the gui and console test runners allow specifying a list of categories to be included in or excluded from the run.
Do the filters need to use your custom attribute, or could you use an NUnit Category? Something like
[Test]
[Category("BugId-12234")]
public void Test()
{
....
}
... and then use the /include=STR
flag:
nunit-console /include=BugId-12234 ...
? I'd recommend subclassing Category to make your custom attribute, but I don't think that allows you to add a switchable parameter to your attribute...
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With