c# - NUnit custom attribute behaving as TestAttribute and CategoryAttribute simultaneously -
i wondering if possible create custom nunit attribute behave categoryattribute , @ same time testattribute.
nunit documentation - test attribute nunit documentation - category attribute
what trying achieve this:
public class unittestattribute : testattribute, categoryattribute, itestaction { public unittestattribute() : base("unittest") public void beforetest(itest test) { /*some logic*/ } public void aftertest(itest test) { /*some logic*/ } public actiontargets targets => actiontargets.test; } unfortunately, not work can not have 2 base classes single class. trying achieve pretty minimalize amount of code have write in order mark test (in case) unit test yet @ same time able filter tests based on category. current code
[test, unittest] public void sometest() { /*doing stuff*/ } will change to
[unittest] public void sometest() { /*doing stuff*/ } and still able run tests using following command
nunit3-console mytest.dll --where "cat == unittest" and vs test explorer find categories etc.
since categoryattribute doesn't set property on test, suggest inherit testattribute , implement category behavior yourself.
you have implement iapplytotest interface. in call iapplytotest, should add (not set) category property of test value want. that's important because test theoretically have additional category annotations.
see code categoryattribute , propertyattribute details. propertyattribute of work. use constant value category find in propertynames.cs
Comments
Post a Comment