-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom attribute that combines Category and Repeat #2589
Comments
This definitely seems like a better solution to me - RepeatAttribute contains a lot more logic you'd need to re-implement - which you haven't done in your example above. You'd need pretty much everything here. Can you share how you attempted this the other way around? What gave you the impression the category wasn't considered? |
ITestAction isn't a suitable interface for your purpose. It performs actions before and after the test, which is not what you are trying to do. Because Repeat is the more complicated attribute, I would derive from that and add the behavior of Category. Repeat Attribute is already derived from Property Attribute, so it has a Properties dictionary to which you can add the category value you want to use. |
I am going to close this as a question since we wouldn't implement this in NUnit itself. If you have trouble, feel free to continue to post here, we will see it. I would suggest that you look a the code for the Repeat and Category attributes to get an idea what they do. https://github.com/nunit/nunit/blob/master/src/NUnitFramework/framework/Attributes/RepeatAttribute.cs |
Thanks @ChrisMaddock and @CharliePoole for your suggestions and ideas! @rprouse thanks! I intended it to be a question. I derived my custom attribute from RepeatAttribute and set the category name by using the Properties dictionary. Here is the code that works for me:
|
@GitSIPA Looks good. Glad we could help. |
Short explanation of what I want to achieve:
I want a custom attribute named "CandidateTest" that sets a category name as well as a Repeat attribute for this test, so that I don't have to use the Repeat separately on my test.
The Reason why I want to do this is that we have a "StressTester" job, that executes all the tests with this category for 50 times each and the test should pass all the 50 executions.
This helps us figure out flaky tests before removing the attribute and letting them run with our normal test set.
The problem here is, that I can't figure out how to set a category as well as setting the Repeat(50).
How I tried to do it:
but it looks like setting the repeat value in BeforeTest is too late for NUnit to be considered.
I also tried it the other way round = CandidateTest is derived from RepeatAttribute and to set the category, but then the category doesn't seem to be considered when executing tests
Any suggestions from your side on how to get this done?
Or is there maybe even a possibility to get a kind of StressTester attribute from NUnit in the future?
The text was updated successfully, but these errors were encountered: