I'm using NUnit and apply on some of my test the category attribute:
[Category("FastTest")]
These are tests that must run very fast ,less than 10 seconds. so I also decorate them with
[Timeout(10000)]
And now the question:
How can I do that every time I decorate a method with [Category("FastTest")] behind the scenes it will be decorated automatically with [Timeout(1000)] ?
SetUpAttribute (NUnit 2.0 / 2.5) This attribute is used inside a TestFixture to provide a common set of functions that are performed just before each test method is called. It is also used inside a SetUpFixture, where it provides the same functionality at the level of a namespace or assembly.
NUnit is basically composed of attributes, or annotations. These indicate to the framework to execute the tests that are implemented in the class, and also how to interpret them.
The [TestFixture] attribute denotes a class that contains unit tests. The [Test] attribute indicates a method is a test method. Save this file and execute the dotnet test command to build the tests and the class library and run the tests. The NUnit test runner contains the program entry point to run your tests.
Create a Resharper live-template that spits out both attributes when writing "catfast" for example. Or buy PostSharp and let postshart AOP-adorn all methods which are marked with the specified category.
I don't think it's very good idea.
Of course you can do it. AOP. Reflection. But simplest way - group all fast tests in one test fixture and decorate it with [Timeout] attribute.
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