Skip to content

How to determine the context for Hooks? (Single method with multiple Hook attributes) #365

Answered by obligaron
DrEsteban asked this question in Q&A
Discussion options

You must be logged in to vote

In your case you could look if a ScenarioContext is present:

        [AfterFeature]
        [AfterScenario]
        public static void MyHook(ITestRunner testRunner)
        {
            bool calledByAfterFeature = testRunner.ScenarioContext is null;
            if (calledByAfterFeature)
            {
                // do AfterFeature stuff
            }
            else
            {
                // do AfterScenario stuff
            }
        }

But as you said, explicit methods would be likely more readable. 😉

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DrEsteban
Comment options

Answer selected by DrEsteban
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants