Order of hook method execution

375 views
Skip to first unread message

kiran

unread,
Jun 18, 2010, 5:22:57 PM6/18/10
to SpecFlow
I have a method that runs before every feature
Another method that runs before all features that are tagged as
"special"

Order of execution seems to be "special" first and then the all
features method.

Is it possible to switch the order? I want the "special" feature hook
method to execute later.

kiran

unread,
Jun 18, 2010, 8:46:50 PM6/18/10
to SpecFlow
I made a small sample and added trace statements in the hook methods,
and found something interesting.

[BeforeFeature]
public static void BeforeTagFeature()
{
Console.WriteLine("Before feature");
}

[BeforeFeature("special")]
public static void BeforeTagFeature()
{
Console.WriteLine("Before special feature");
}


If both hook methods are in the same project, following is the output

before feature
before special feaure

If they are in different projects, and assembly that has @special tag
has the app.config and refers the base assembly. The order is
reversed

before special feature
before feature


-Kiran

Alice Waddicor

unread,
Mar 15, 2015, 7:12:30 AM3/15/15
to spec...@googlegroups.com
Does anyone know if there are any plans to introduce the ability to order hooks for the same event? 

For example, I want to use a hook to delete the data generated by a test from storage, and this needs to run before I shut down our DI container. We have a package that provides a hook for DI container setup and shut down at scenario level, but the undefined execution order of hooks for the same event means I can't reliably combine it with a @delete_test_data hook at scenario level.

I've ended up not using the DI container hook package, and instead writing a combined hook, but it would be nicer to have a simple way to control the order.

Sam Holder

unread,
Mar 16, 2015, 4:10:08 PM3/16/15
to specflow
Yes this is one of the features that is scheduled for V2 I believe. it just needs someone to implement it. :)

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Umair Chagani

unread,
Mar 16, 2015, 6:13:19 PM3/16/15
to spec...@googlegroups.com
I think the order of the hooks should be implicit rather than explicit.  It becomes just one more thing to manage if it is explicit.  For example, in cucumber, the execution of the hooks depends on the order in which they are registered.  I think we can take this one step further, maybe something like:

BeforeTestRun- General
BeforeTestRun- Scoped
BeforeScenario - General
BeforeScenario - Scoped
BeforeScenarioBlock - General
BeforeScenarioBlock - Scoped
BeforeStep - General 
BeforeStep - Scoped

And the inverse of the above for all the After steps.  If there are multiple items of the same scope we can either execute them in the order that it is registered, or we can choose to not guarantee the order of similarly scoped steps at all.

Thoughts?


Gáspár Nagy

unread,
Mar 17, 2015, 3:39:16 AM3/17/15
to spec...@googlegroups.com, umair....@gmail.com
I think with the introduction of the order/priority, we will have a tool for specifying hook order. In my opinion, combining this with another (implicit) ordering is confusing. Ie. the case when I have a scoped before hook prioritized up explicitly vs. a general hook without explicit priority.

So as a first step, I would only do the explicit ordering and not define any implicit one (within the same hook of course). This is anyway a rare case (i needed it only 3-4 times in the past 6 years) and easy to workaround.

Br,
Gaspar


On Monday, March 16, 2015 at 11:13:19 PM UTC+1, uchagani wrote:
I think the order of the hooks should be implicit rather than explicit.  It becomes just one more thing to manage if it is explicit.  For example, in cucumber, the execution of the hooks depends on the order in which they are registered.  I think we can take this one step further, maybe something like:

BeforeTestRun- General
BeforeTestRun- Scoped
BeforeScenario - General
BeforeScenario - Scoped
BeforeScenarioBlock - General
BeforeScenarioBlock - Scoped
BeforeStep - General 
BeforeStep - Scoped

And the inverse of the above for all the After steps.  If there are multiple items of the same scope we can either execute them in the order that it is registered, or we can choose to not guarantee the order of similarly scoped steps at all.

Thoughts?


On Mon, Mar 16, 2015 at 4:10 PM, Sam Holder wrote:
Yes this is one of the features that is scheduled for V2 I believe. it just needs someone to implement it. :)
On Fri, Mar 13, 2015 at 11:52 AM, Alice Waddicor wrote:
Does anyone know if there are any plans to introduce the ability to order hooks for the same event? 

For example, I want to use a hook to delete the data generated by a test from storage, and this needs to run before I shut down our DI container. We have a package that provides a hook for DI container setup and shut down at scenario level, but the undefined execution order of hooks for the same event means I can't reliably combine it with a @delete_test_data hook at scenario level.

I've ended up not using the DI container hook package, and instead writing a combined hook, but it would be nicer to have a simple way to control the order.

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages