-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #10 Scenarios are now isolated one from another. No params or b…
…ody will be spilled to next Scenario
- Loading branch information
1 parent
d7f1d3a
commit 6eb6e9c
Showing
5 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
18 changes: 15 additions & 3 deletions
18
cukes-rest-sample/src/test/resources/healthcheck/healthcheck.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 |
---|---|---|
@@ -1,6 +1,18 @@ | ||
Feature: Server is healthy | ||
|
||
Scenario: Should return pong response on /ping | ||
When the client performs GET request on /ping | ||
Background: | ||
Given baseUri is http://localhost:8888/ | ||
|
||
Scenario: Should return pong response on /healthcheck | ||
When the client performs GET request on /healthcheck | ||
Then status code is 200 | ||
|
||
Scenario: Scenario is isolated from another | ||
When the client performs GET request on /healthcheck | ||
Then status code is 200 | ||
Given request body "Hello. I'm Isolated!" | ||
Given queryParam "param" is "isolated" | ||
|
||
Scenario: GET is performed without extra request body | ||
When the client performs GET request on /healthcheck | ||
Then status code is 200 | ||
And response equals to "pong" |
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
24 changes: 24 additions & 0 deletions
24
cukes-rest/src/main/java/lv/ctco/cukesrest/api/CucumberHooks.java
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,24 @@ | ||
package lv.ctco.cukesrest.api; | ||
|
||
import com.google.inject.*; | ||
import cucumber.api.java.*; | ||
import lv.ctco.cukesrest.internal.*; | ||
|
||
public class CucumberHooks { | ||
|
||
@Inject | ||
CucumberFacade cucumberFacade; | ||
|
||
@Before | ||
public void beforeScenario() { | ||
if (cucumberFacade.firstScenario()) { | ||
cucumberFacade.beforeAllTests(); | ||
} | ||
cucumberFacade.beforeScenario(); | ||
} | ||
|
||
@After | ||
public void afterScenario() { | ||
cucumberFacade.afterScenario(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
cukes-rest/src/main/java/lv/ctco/cukesrest/internal/CucumberFacade.java
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,55 @@ | ||
package lv.ctco.cukesrest.internal; | ||
|
||
import com.google.inject.*; | ||
import lv.ctco.cukesrest.*; | ||
|
||
import java.util.*; | ||
|
||
@Singleton | ||
public class CucumberFacade { | ||
|
||
/* Ugly Hack proposed by Cucumber developers: https://github.com/cucumber/cucumber-jvm/pull/295 */ | ||
public static boolean firstRun = true; | ||
|
||
@Inject | ||
Set<CukesRestPlugin> pluginSet; | ||
|
||
@Inject | ||
RequestSpecificationFacade requestSpecificationFacade; | ||
|
||
public boolean firstScenario() { | ||
return firstRun; | ||
} | ||
|
||
public void beforeAllTests() { | ||
firstRun = false; | ||
for (CukesRestPlugin cukesRestPlugin : pluginSet) { | ||
cukesRestPlugin.beforeAllTests(); | ||
} | ||
Runtime.getRuntime().addShutdownHook(new Thread() { | ||
@Override | ||
public void run() { | ||
afterAllTests(); | ||
} | ||
}); | ||
} | ||
|
||
public void beforeScenario() { | ||
for (CukesRestPlugin cukesRestPlugin : pluginSet) { | ||
cukesRestPlugin.beforeScenario(); | ||
} | ||
} | ||
|
||
public void afterScenario() { | ||
for (CukesRestPlugin cukesRestPlugin : pluginSet) { | ||
cukesRestPlugin.afterScenario(); | ||
} | ||
requestSpecificationFacade.initNewSpecification(); | ||
} | ||
|
||
public void afterAllTests() { | ||
for (CukesRestPlugin cukesRestPlugin : pluginSet) { | ||
cukesRestPlugin.afterAllTests(); | ||
} | ||
} | ||
} |
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