Search in sources :

Example 21 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldAllowToNotResetStateBeforeStory.

@Test
public void shouldAllowToNotResetStateBeforeStory() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step failedStep = mock(Step.class, "failedStep");
    when(failedStep.perform(null)).thenReturn(failed("before stories", new UUIDExceptionWrapper(new RuntimeException("BeforeStories fail"))));
    Step pendingStep = mock(Step.class, "pendingStep");
    when(pendingStep.perform(null)).thenReturn(pending("pendingStep"));
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario1 = new Scenario();
    List<CandidateSteps> candidateSteps = asList(mySteps);
    when(collector.collectBeforeOrAfterStoriesSteps(candidateSteps, Stage.BEFORE)).thenReturn(asList(failedStep));
    when(collector.collectScenarioSteps(candidateSteps, scenario1, parameters)).thenReturn(asList(pendingStep));
    Story story = new Story(asList(scenario1));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(reporter, collector);
    configuration.storyControls().doResetStateBeforeStory(false).doResetStateBeforeScenario(false);
    runner.runBeforeOrAfterStories(configuration, candidateSteps, Stage.BEFORE);
    runner.run(configuration, candidateSteps, story);
    // Then
    verify(failedStep).perform(Matchers.<UUIDExceptionWrapper>any());
    verify(pendingStep).perform(Matchers.<UUIDExceptionWrapper>any());
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) Test(org.junit.Test)

Example 22 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldRunGivenStoriesAtStoryAndScenarioLevel.

@Test
public void shouldRunGivenStoriesAtStoryAndScenarioLevel() throws Throwable {
    // Given
    GivenStories storyGivenStories = new GivenStories("/path/to/given/story1");
    GivenStories scenarioGivenStories = new GivenStories("/path/to/given/story1");
    Scenario scenario1 = new Scenario("scenario 1", asList("successfulStep"));
    Scenario scenario2 = new Scenario("scenario 2", Meta.EMPTY, scenarioGivenStories, ExamplesTable.EMPTY, asList("anotherSuccessfulStep"));
    Story story1 = new Story(new Description("story 1"), Narrative.EMPTY, asList(scenario1));
    Story story2 = new Story("", new Description("story 2"), Meta.EMPTY, Narrative.EMPTY, storyGivenStories, asList(scenario2));
    Step step = mock(Step.class);
    StepResult result = mock(StepResult.class);
    when(step.perform(null)).thenReturn(result);
    StoryParser storyParser = mock(StoryParser.class);
    StoryLoader storyLoader = mock(StoryLoader.class);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Step successfulStep = mockSuccessfulStep("successfulStep");
    Step anotherSuccessfulStep = mockSuccessfulStep("anotherSuccessfulStep");
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story1, givenStory, collector, mySteps);
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(successfulStep));
    givenStoryWithNoBeforeOrAfterSteps(story2, givenStory, collector, mySteps);
    when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(anotherSuccessfulStep));
    when(storyLoader.loadStoryAsText("/path/to/given/story1")).thenReturn("storyContent");
    when(storyParser.parseStory("storyContent", "/path/to/given/story1")).thenReturn(story1);
    givenStoryWithNoBeforeOrAfterSteps(story1, givenStory, collector, mySteps);
    givenStoryWithNoBeforeOrAfterSteps(story2, givenStory, collector, mySteps);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(storyParser, storyLoader, reporter, collector, failureStrategy);
    runner.run(configuration, asList(mySteps), story2);
    // Then
    InOrder inOrder = inOrder(reporter);
    inOrder.verify(reporter).beforeStory(story2, givenStory);
    inOrder.verify(reporter).givenStories(storyGivenStories);
    inOrder.verify(reporter).givenStories(scenarioGivenStories);
    inOrder.verify(reporter).successful("successfulStep");
    inOrder.verify(reporter).successful("anotherSuccessfulStep");
    inOrder.verify(reporter).afterStory(givenStory);
    verify(reporter, never()).beforeStory(story1, givenStory);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) StoryLoader(org.jbehave.core.io.StoryLoader) InOrder(org.mockito.InOrder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) StoryParser(org.jbehave.core.parsers.StoryParser) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) Test(org.junit.Test)

Example 23 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldResetStateBeforeScenario.

@Test
public void shouldResetStateBeforeScenario() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step pendingStep = mock(Step.class);
    when(pendingStep.perform(null)).thenReturn(pending("pendingStep"));
    Step secondStep = mockSuccessfulStep("secondStep");
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario1 = new Scenario();
    Scenario scenario2 = new Scenario();
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(pendingStep));
    when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(secondStep));
    Story story = new Story(asList(scenario1, scenario2));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(reporter, collector);
    configuration.storyControls().doResetStateBeforeScenario(true);
    runner.run(configuration, asList(mySteps), story);
    // Then
    verify(pendingStep).perform(Matchers.<UUIDExceptionWrapper>any());
    verify(secondStep).perform(Matchers.<UUIDExceptionWrapper>any());
    verify(secondStep, never()).doNotPerform(Matchers.<UUIDExceptionWrapper>any());
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) Test(org.junit.Test)

Example 24 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldAllowToSkipScenariosAfterFailedScenario.

@Test
public void shouldAllowToSkipScenariosAfterFailedScenario() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step failedStep = mock(Step.class);
    Step neverExecutedStep = mock(Step.class);
    StepResult failed = failed("When I fail", new UUIDExceptionWrapper(new IllegalStateException()));
    when(failedStep.perform(null)).thenReturn(failed);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario1 = new Scenario();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), eq(scenario1), eq(parameters))).thenReturn(asList(failedStep));
    Scenario scenario2 = new Scenario();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), eq(scenario2), eq(parameters))).thenReturn(asList(neverExecutedStep));
    Story story = new Story(asList(scenario1, scenario2));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(reporter, collector, failureStrategy);
    configuration.storyControls().doSkipScenariosAfterFailure(true);
    runner.run(configuration, asList(mySteps), story);
    // Then
    verify(failedStep).perform(null);
    verify(neverExecutedStep, never()).perform(null);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) Test(org.junit.Test)

Example 25 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldReportFailuresInStepsBeforeAndAfterStories.

@Test
public void shouldReportFailuresInStepsBeforeAndAfterStories() throws Throwable {
    // Given
    Step beforeStep = mock(Step.class, "beforeStep");
    StepResult beforeResult = mock(StepResult.class, "beforeStep");
    when(beforeStep.perform(null)).thenReturn(beforeResult);
    UUIDExceptionWrapper failure = new UUIDExceptionWrapper("failed");
    when(beforeResult.getFailure()).thenReturn(failure);
    Step afterStep = mock(Step.class, "afterStep");
    StepResult afterResult = mock(StepResult.class);
    when(afterStep.doNotPerform(failure)).thenReturn(afterResult);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    StoryReporter reporter = mock(StoryReporter.class);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    // When
    StoryRunner runner = new StoryRunner();
    when(collector.collectBeforeOrAfterStoriesSteps(asList(mySteps), Stage.BEFORE)).thenReturn(asList(beforeStep));
    runner.runBeforeOrAfterStories(configurationWith(reporter, collector, failureStrategy), asList(mySteps), Stage.BEFORE);
    when(collector.collectBeforeOrAfterStoriesSteps(asList(mySteps), Stage.AFTER)).thenReturn(asList(afterStep));
    runner.runBeforeOrAfterStories(configurationWith(reporter, collector, failureStrategy), asList(mySteps), Stage.AFTER);
    // Then
    verify(beforeStep).perform(null);
    verify(afterStep).doNotPerform(failure);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) Test(org.junit.Test)

Aggregations

StoryReporter (org.jbehave.core.reporters.StoryReporter)32 Test (org.junit.Test)32 ConcurrentStoryReporter (org.jbehave.core.reporters.ConcurrentStoryReporter)24 AbstractStep (org.jbehave.core.steps.StepCreator.AbstractStep)19 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)16 Configuration (org.jbehave.core.configuration.Configuration)15 AbstractStepResult (org.jbehave.core.steps.AbstractStepResult)10 InOrder (org.mockito.InOrder)8 Method (java.lang.reflect.Method)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)2 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)2 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)2 BatchFailures (org.jbehave.core.failures.BatchFailures)2 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)2