-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:techtalk/SpecFlow
- Loading branch information
Showing
5 changed files
with
333 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Tests/FeatureTests/BeforeAfterHooks/BeforeAfterHooks.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Feature: Addition | ||
As a developer | ||
I would like to be able to hook into pre and post conditions in SpecFlow | ||
So that I can set up and teardown my scenario accordingly | ||
|
||
Scenario: Hooking into pre conditions for Test Runs in SpecFlow | ||
Given the scenario is running | ||
Then the BeforeTestRun hook should have been executed | ||
|
||
Scenario: Hooking into pre conditions for Features in SpecFlow | ||
Given the scenario is running | ||
Then the BeforeFeature hook should have been executed | ||
|
||
Scenario: Hooking into pre conditions for Scenarios in SpecFlow | ||
Given the scenario is running | ||
Then the BeforeScenario hook should have been executed | ||
|
||
Scenario: Hooking into pre conditions for ScenarioBlocks in SpecFlow | ||
Given the scenario is running | ||
Then the BeforeScenarioBlock hook should have been executed | ||
|
||
Scenario: Hooking into pre conditions for Steps in SpecFlow | ||
Given the scenario is running | ||
Then the BeforeStep hook should have been executed | ||
|
132 changes: 132 additions & 0 deletions
132
Tests/FeatureTests/BeforeAfterHooks/BeforeAfterHooks.feature.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
Tests/FeatureTests/BeforeAfterHooks/BeforeAfterHooksSteps.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace TechTalk.SpecFlow.FeatureTests.BeforeAfterHooks | ||
{ | ||
[Binding] | ||
public class BeforeAfterHooksSteps | ||
{ | ||
private static bool _beforeTestRunHookExecuted; | ||
private static bool _beforeFeatureHookExecuted; | ||
private bool _beforeScenarioHookExecuted; | ||
private bool _beforeScenarioBlockHookExecuted; | ||
private bool _beforeStepHookExecuted; | ||
private static bool _afterFeatureHookExecuted; | ||
private static bool _afterScenarioHookExecuted; | ||
private static bool _afterScenarioBlockHookExecuted; | ||
private static bool _afterStepHookExecuted; | ||
|
||
[BeforeTestRun] | ||
public static void BeforeTestRun() | ||
{ | ||
_beforeTestRunHookExecuted = true; | ||
} | ||
|
||
[BeforeFeature] | ||
public static void BeforeFeature() | ||
{ | ||
_beforeFeatureHookExecuted = true; | ||
} | ||
|
||
[BeforeScenario] | ||
public void BeforeScenario() | ||
{ | ||
_beforeScenarioHookExecuted = true; | ||
} | ||
|
||
[BeforeScenarioBlock] | ||
public void BeforeScenarioBlock() | ||
{ | ||
_beforeScenarioBlockHookExecuted = true; | ||
} | ||
|
||
[BeforeStep] | ||
public void BeforeStep() | ||
{ | ||
_beforeStepHookExecuted = true; | ||
} | ||
|
||
[AfterTestRun] | ||
public static void AfterTestRun() | ||
{ | ||
// Testing AfterTestRun is tricky as it would probably involve manipulating the AppDomain | ||
// Its been manually tested and verified that this code block is hit, but if something changes | ||
// which stops it from being called, we'll never know... | ||
|
||
Assert.That(_afterFeatureHookExecuted, Is.True); | ||
Assert.That(_afterScenarioHookExecuted, Is.True); | ||
Assert.That(_afterScenarioBlockHookExecuted, Is.True); | ||
Assert.That(_afterStepHookExecuted, Is.True); | ||
} | ||
|
||
[AfterFeature] | ||
public static void AfterFeature() | ||
{ | ||
_afterFeatureHookExecuted = true; | ||
} | ||
|
||
[AfterScenario] | ||
public void AfterScenario() | ||
{ | ||
_afterScenarioHookExecuted = true; | ||
} | ||
|
||
[AfterScenarioBlock] | ||
public void AfterScenarioBlock() | ||
{ | ||
_afterScenarioBlockHookExecuted = true; | ||
} | ||
|
||
[AfterStep] | ||
public void AfterStep() | ||
{ | ||
_afterStepHookExecuted = true; | ||
} | ||
|
||
[Given(@"the scenario is running")] | ||
public void GivenTheScenarioIsRunning() | ||
{ | ||
} | ||
|
||
[Then(@"the BeforeTestRun hook should have been executed")] | ||
public void ThenTheBeforeTestRunHookShouldHaveBeenExecuted() | ||
{ | ||
Assert.That(_beforeTestRunHookExecuted, Is.True); | ||
} | ||
|
||
[Then(@"the BeforeFeature hook should have been executed")] | ||
public void ThenTheBeforeFeatureHookShouldHaveBeenExecuted() | ||
{ | ||
Assert.That(_beforeFeatureHookExecuted, Is.True); | ||
} | ||
|
||
[Then(@"the BeforeScenario hook should have been executed")] | ||
public void ThenTheBeforeScenarioHookShouldHaveBeenExecuted() | ||
{ | ||
Assert.That(_beforeScenarioHookExecuted, Is.True); | ||
} | ||
|
||
[Then(@"the BeforeScenarioBlock hook should have been executed")] | ||
public void ThenTheBeforeScenarioBlockHookShouldHaveBeenExecuted() | ||
{ | ||
Assert.That(_beforeScenarioBlockHookExecuted, Is.True); | ||
} | ||
|
||
[Then(@"the BeforeStep hook should have been executed")] | ||
public void ThenTheBeforeStepHookShouldHaveBeenExecuted() | ||
{ | ||
Assert.That(_beforeStepHookExecuted, Is.True); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters