| @@ -0,0 +1,19 @@ | ||
| package net.thucydides.jbehave.internals; | ||
|
|
||
| /** | ||
| * Keeps track of instantiated JBehave step libraries used in Thucydides tests. | ||
| */ | ||
| public class ThucydidesStepContext { | ||
|
|
||
| public ThucydidesStepContext() { | ||
| } | ||
|
|
||
| public Object newInstanceOf(Class<?> type) { | ||
| try { | ||
| return type.newInstance(); | ||
| } catch (Exception e) { | ||
| throw new ThucydidesStepInitializationError(e); | ||
| } | ||
| } | ||
| } | ||
|
|
| @@ -0,0 +1,7 @@ | ||
| package net.thucydides.jbehave.internals; | ||
|
|
||
| public class ThucydidesStepInitializationError extends RuntimeException { | ||
| public ThucydidesStepInitializationError(Exception cause) { | ||
| super(cause); | ||
| } | ||
| } |
| @@ -1,4 +1,4 @@ | ||
| package net.thucydides.jbehave.reflection; | ||
|
|
||
| import java.lang.reflect.Field; | ||
|
|
||
| @@ -0,0 +1,59 @@ | ||
| package net.thucydides.jbehave; | ||
|
|
||
| import net.thucydides.core.model.TestOutcome; | ||
| import net.thucydides.core.reports.xml.XMLTestOutcomeReporter; | ||
| import net.thucydides.core.util.MockEnvironmentVariables; | ||
| import net.thucydides.core.webdriver.Configuration; | ||
| import net.thucydides.core.webdriver.SystemPropertiesConfiguration; | ||
| import org.jbehave.core.reporters.StoryReporter; | ||
| import org.jbehave.core.reporters.TxtOutput; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.rules.TemporaryFolder; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.io.PrintStream; | ||
| import java.util.List; | ||
|
|
||
| public class AbstractJBehaveStory { | ||
| protected OutputStream output; | ||
| protected StoryReporter printOutput; | ||
|
|
||
| protected MockEnvironmentVariables environmentVariables; | ||
| protected Configuration systemConfiguration; | ||
|
|
||
| @Rule | ||
| public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
|
||
| protected File outputDirectory; | ||
|
|
||
| @Before | ||
| public void prepareReporter() { | ||
|
|
||
| environmentVariables = new MockEnvironmentVariables(); | ||
|
|
||
| outputDirectory = temporaryFolder.newFolder("output"); | ||
| environmentVariables.setProperty("thucydides.outputDirectory", outputDirectory.getAbsolutePath()); | ||
|
|
||
| output = new ByteArrayOutputStream(); | ||
| printOutput = new TxtOutput(new PrintStream(output)); | ||
| systemConfiguration = new SystemPropertiesConfiguration(environmentVariables); | ||
| } | ||
|
|
||
|
|
||
| protected void run(JUnitThucydidesStories stories) { | ||
| try { | ||
| stories.run(); | ||
| } catch(Throwable e) { | ||
| // Ignore | ||
| } | ||
| } | ||
|
|
||
| protected List<TestOutcome> loadTestOutcomes() throws IOException { | ||
| XMLTestOutcomeReporter outcomeReporter = new XMLTestOutcomeReporter(); | ||
| return outcomeReporter.loadReportsFrom(outputDirectory); | ||
| } | ||
| } |
| @@ -0,0 +1,92 @@ | ||
| package net.thucydides.jbehave; | ||
|
|
||
| import net.thucydides.core.model.TestOutcome; | ||
| import net.thucydides.core.model.TestResult; | ||
| import net.thucydides.core.reports.xml.XMLTestOutcomeReporter; | ||
| import net.thucydides.core.util.MockEnvironmentVariables; | ||
| import net.thucydides.core.webdriver.Configuration; | ||
| import net.thucydides.core.webdriver.SystemPropertiesConfiguration; | ||
| import org.jbehave.core.reporters.StoryReporter; | ||
| import org.jbehave.core.reporters.TxtOutput; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.io.PrintStream; | ||
| import java.util.List; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| public class WhenRunningJBehaveStories extends AbstractJBehaveStory { | ||
|
|
||
| private static final int TOTAL_NUMBER_OF_JBEHAVE_SCENARIOS = 8; | ||
|
|
||
| final class AllStories extends JUnitThucydidesStories {} | ||
|
|
||
| @Test | ||
| public void all_stories_on_the_classpath_should_be_run_by_default() throws Throwable { | ||
|
|
||
| // Given | ||
| JUnitThucydidesStories stories = new AllStories(); | ||
| stories.setSystemConfiguration(systemConfiguration); | ||
| stories.configuredEmbedder().configuration().storyReporterBuilder().withReporters(printOutput); | ||
|
|
||
| // When | ||
| run(stories); | ||
|
|
||
| // Then | ||
| List<TestOutcome> outcomes = loadTestOutcomes(); | ||
| assertThat(outcomes.size(), is(TOTAL_NUMBER_OF_JBEHAVE_SCENARIOS)); | ||
| } | ||
|
|
||
| final class StoriesInTheSubsetFolder extends JUnitThucydidesStories { | ||
| public void configure() { | ||
| findStoriesIn("stories/subset"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void a_subset_of_the_stories_can_be_run_individually() throws Throwable { | ||
|
|
||
| // Given | ||
| JUnitThucydidesStories stories = new StoriesInTheSubsetFolder(); | ||
| stories.setSystemConfiguration(systemConfiguration); | ||
| stories.configuredEmbedder().configuration().storyReporterBuilder().withReporters(printOutput); | ||
|
|
||
| // When | ||
| run(stories); | ||
|
|
||
| // Then | ||
|
|
||
| List<TestOutcome> outcomes = loadTestOutcomes(); | ||
| assertThat(outcomes.size(), is(2)); | ||
| } | ||
|
|
||
| final class SomePassingStories extends JUnitThucydidesStories { | ||
| public void configure() { | ||
| findStoriesCalled("*PassingStory.story"); | ||
| } | ||
| } | ||
| @Test | ||
| public void stories_with_a_matching_name_can_be_run() throws Throwable { | ||
|
|
||
| // Given | ||
| JUnitThucydidesStories stories = new SomePassingStories(); | ||
| stories.setSystemConfiguration(systemConfiguration); | ||
| stories.configuredEmbedder().configuration().storyReporterBuilder().withReporters(printOutput); | ||
|
|
||
| // When | ||
| run(stories); | ||
|
|
||
| // Then | ||
| List<TestOutcome> outcomes = loadTestOutcomes(); | ||
| assertThat(outcomes.size(), is(3)); | ||
| } | ||
|
|
||
| } |
| @@ -1,10 +1,4 @@ | ||
| package net.thucydides.jbehave.samples; | ||
|
|
||
| public class SampleJBehaveSteps { | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| package net.thucydides.jbehave.steps; | ||
|
|
||
| import net.thucydides.core.annotations.Step; | ||
|
|
||
| public class SomeThucydidesSteps { | ||
|
|
||
| @Step | ||
| public void step1() {} | ||
|
|
||
| @Step | ||
| public void step2() {} | ||
|
|
||
| @Step | ||
| public void step3() {} | ||
| } |
| @@ -0,0 +1,42 @@ | ||
| package net.thucydides.jbehave.steps; | ||
|
|
||
| import org.jbehave.core.annotations.Given; | ||
| import org.jbehave.core.annotations.Pending; | ||
| import org.jbehave.core.annotations.Then; | ||
| import org.jbehave.core.annotations.When; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| public class StorySteps { | ||
| @Given("I have an implemented JBehave scenario") | ||
| public void givenIHaveAnImplementedJBehaveScenario() { | ||
| } | ||
|
|
||
| @Given("the scenario works") | ||
| public void givenTheScenarioWorks() { | ||
| } | ||
|
|
||
| @When("I run the scenario") | ||
| public void whenIRunTheScenario() { | ||
| } | ||
|
|
||
| @Then("I should get a successful result") | ||
| public void thenIShouldGetASuccessfulResult() { | ||
| } | ||
|
|
||
| @Given("the scenario fails") | ||
| public void givenTheScenarioFails() { | ||
| } | ||
|
|
||
| @Then("I should get a failed result") | ||
| public void thenIShouldGetAFailedResult() { | ||
| assertThat(true,is(false)); | ||
| } | ||
|
|
||
| @Given("a JBehave story with a pending implementation") | ||
| @Pending | ||
| public void aJBehaveStoryWithAPendingImplementation() {} | ||
|
|
||
|
|
||
| } |
| @@ -0,0 +1,28 @@ | ||
| package net.thucydides.jbehave.steps; | ||
|
|
||
| import net.thucydides.core.annotations.Steps; | ||
| import org.jbehave.core.annotations.Given; | ||
| import org.jbehave.core.annotations.Pending; | ||
| import org.jbehave.core.annotations.Then; | ||
| import org.jbehave.core.annotations.When; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| public class StoryStepsWithThucydidesSteps { | ||
|
|
||
| @Steps | ||
| SomeThucydidesSteps steps; | ||
|
|
||
| @Given("the scenario has steps") | ||
| public void givenTheScenarioHasSteps() { | ||
| steps.step1(); | ||
| steps.step2(); | ||
| steps.step3(); | ||
| } | ||
|
|
||
| @Then("the steps should appear in the outcome") | ||
| public void thenTheStepsShouldAppearInTheOutcome() { | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,6 @@ | ||
| Scenario: A scenario that works | ||
|
|
||
| Given I have an implemented JBehave scenario | ||
| And the scenario fails | ||
| When I run the scenario | ||
| Then I should get a failed result |
| @@ -1,15 +1,6 @@ | ||
| Scenario: A scenario that works | ||
|
|
||
| Given I have an implemented JBehave scenario | ||
| And the scenario works | ||
| When I run the scenario | ||
| Then I should get a successful result |
| @@ -0,0 +1,6 @@ | ||
| Scenario: A scenario using steps | ||
|
|
||
| Given I have an implemented JBehave scenario | ||
| And the scenario has steps | ||
| When I run the scenario | ||
| Then the steps should appear in the outcome |
| @@ -0,0 +1,5 @@ | ||
| Scenario: A scenario with implemented pending steps | ||
|
|
||
| Given a JBehave story with a pending implementation | ||
| When the story is executed | ||
| Then the steps should be marked as pending |
| @@ -0,0 +1,8 @@ | ||
| import org.jbehave.core.annotations.Then | ||
|
|
||
| Scenario: A scenario with pending steps | ||
|
|
||
| Given JBehave story with no implementation | ||
| When the story is executed | ||
| Then the steps should be marked as pending | ||
| And sample implementations should be proposed |
| @@ -0,0 +1,19 @@ | ||
| package stories.subset | ||
|
|
||
| import org.jbehave.core.annotations.Given | ||
|
|
||
| Scenario: A scenario with groovy steps | ||
|
|
||
| Given a date of 10/16/2010 | ||
| When 4 days pass | ||
| Then the date is 10/18/2010 | ||
| And some otherwise ambiguous two string step, with one and two as strings | ||
|
|
||
|
|
||
| Scenario: Another scenario with groovy steps | ||
|
|
||
| Given a date of 10/16/2010 | ||
| When 4 days pass | ||
| Then the date is 10/18/2010 | ||
| And some otherwise ambiguous two string step, with one and two as strings | ||
|
|