Enable specifying the execution order of Action Attributes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
NUnit Framework |
New
|
Undecided
|
Unassigned |
Bug Description
In the Action Attribute documentation, it says, "Note that the order in which attributes are applied is indeterminate, although it will generally be stable for a single release of .NET."
What about creating an interface like this:
public interface IOrderedTestAction : ITestAction
{
int Order { get; }
}
This way, one could specify the order of execution of the different attributes on a test.
For instance, we might have an attribute setting up dependency injection, and another one depending on it, which always should be run after it.
NUnit could then give attributes that only implement ITestAction a default order, and then execute them in the specified order.
Some of this could be solved by using base classes, as suggested here: https:/
However, that seems to defeat the purpose of Action Attributes, namely the possibility of composing them freely on individual tests or fixtures, without resorting to base classes (see "The Problem of Composability" here: http://
When the actions are independent of one another, the test code using them turns out quite elegant. However, I have run into a few scenarios where order matters, and the absence of some way to order the attributes forces inheritance or copy-pasted code. Much welcome refactoring could be done on some of my project's test files if I could define an order of execution.