This project is read-only.

Can't get hooks to work

Apr 5, 2013 at 9:41 PM
I've created a "global" hooks class as per the docs, which is not inside any namespace and looks like this:

public class MyHooks
    private void OnBeforeScenario()
        ScenarioContext.Current["DataHelper"] = new TestDataHelper();

    public void OnAfterScenario()
        var dataHelper = (TestDataHelper)ScenarioContext.Current["DataHelper"];
        if (dataHelper != null)

However, when I run my tests, neither of the hooks is called. What am I doing wrong here?

Apr 7, 2013 at 10:10 PM
From your other post I assume you are using the fluent interface, if so then hooks doesnt work, they only work when running gherkin files.
You could override MainSetup and MainTeardown.
Apr 7, 2013 at 10:40 PM
Edited Apr 7, 2013 at 10:41 PM
Thanks for the reply... I think MainSetup and MainTeardown are in the ScenarioDrivenSpecBase class, which doesn't help much (I could simply use ClassInitialize and ClassCleanup in mstest to do that). Ideally I was after something that I could use in the ActionSteps helper, since it would avoid having to use static properties and potential issues if/when multiple tests are run concurrently.

It seems the obselete NBehave.Narrator.Framework.BeforeScenarioAttribute still works with the fluent interface though, so I'm using that instead. Hopefully it doesn't get pulled from the code completely in future releases :(
Apr 8, 2013 at 9:21 PM
The obsolete attributes are already gone in my 0.7 branch, but on the bright side I just spent an hour implementing Before-/After-Scenario/Step hooks for the fluent interface. It should only require to add a single using statement when upgrading.
Apr 8, 2013 at 9:56 PM
It seems your alias is somewhat of a misnomer then :)

Thank you!