Skip to content

Commit

Permalink
Merge pull request #49 from YamStranger/test_reorganisation
Browse files Browse the repository at this point in the history
Tests are reorganised  to enable as more parallel tests as it possible
  • Loading branch information
YamStranger committed Feb 24, 2016
2 parents cf10c32 + 685490b commit 6e02df9
Show file tree
Hide file tree
Showing 12 changed files with 973 additions and 739 deletions.
651 changes: 0 additions & 651 deletions src/test/java/net/serenitybdd/jbehave/WhenRunningJBehaveStories.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package net.serenitybdd.jbehave;

import net.thucydides.core.model.TestOutcome;
import net.thucydides.core.model.TestResult;
import net.thucydides.core.util.EnvironmentVariables;
import org.junit.Test;

import java.util.List;

import static net.thucydides.core.matchers.PublicThucydidesMatchers.containsResults;
import static net.thucydides.core.model.TestResult.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class WhenRunningJBehaveStoriesWithError extends AbstractJBehaveStory {

final static class AStorySample extends SerenityStories {

public AStorySample(EnvironmentVariables environmentVariables) {
super(environmentVariables);
}

protected AStorySample(String storyName) {
findStoriesCalled(storyName);
}
}

@Test
public void stories_with_errors_should_be_reported_as_failing() throws Throwable {

// Given
SerenityStories failingStory = newStory("aBehaviorThrowingAnException.story");

// When
run(failingStory);

// Then
List<TestOutcome> outcomes = loadTestOutcomes();
assertThat(outcomes.size(), is(1));
assertThat(outcomes.get(0).getResult(), is(TestResult.ERROR));
}

private void runStories(SerenityStories stories) throws Throwable {
run(stories);
}

@Test
public void errored_stories_should_be_reported_as_having_an_error() throws Throwable {

// Given
SerenityStories failingStory = newStory("aBehaviorWithAnError.story");

// When
run(failingStory);

// Then
List<TestOutcome> outcomes = loadTestOutcomes();
assertThat(outcomes.size(), is(1));
assertThat(outcomes.get(0).getResult(), is(TestResult.ERROR));
}

@Test
public void a_test_running_a_failing_story_should_fail() throws Throwable {
SerenityStories stories = new AFailingBehavior();
stories.setSystemConfiguration(systemConfiguration);
runStories(stories);

assert !raisedErrors.isEmpty();
}

@Test
public void a_test_running_a_failing_story_among_several_should_fail() throws Throwable {
SerenityStories stories = new ASetOfBehaviorsContainingFailures();
stories.setSystemConfiguration(systemConfiguration);
runStories(stories);

assert !raisedErrors.isEmpty();
}

@Test
public void failing_stories_run_in_junit_should_fail() throws Throwable {

// Given
SerenityStories failingStory = newStory("aFailingBehavior.story");

// When
runStories(failingStory);

assert !raisedErrors.isEmpty();
}

@Test
public void stories_with_errors_run_in_junit_should_fail() throws Throwable {

// Given
SerenityStories failingStory = newStory("aBehaviorThrowingAnException.story");

// When
runStories(failingStory);

assert !raisedErrors.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.serenitybdd.jbehave;

import net.thucydides.core.model.TestOutcome;
import net.thucydides.core.model.TestResult;
import net.thucydides.core.util.EnvironmentVariables;
import org.junit.Test;

import java.util.List;

import static net.thucydides.core.model.TestResult.FAILURE;
import static net.thucydides.core.model.TestResult.SUCCESS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class WhenRunningJBehaveStoriesWithFailure extends AbstractJBehaveStory {

final static class AStorySample extends SerenityStories {

public AStorySample(EnvironmentVariables environmentVariables) {
super(environmentVariables);
}

protected AStorySample(String storyName) {
findStoriesCalled(storyName);
}
}

@Test
public void failing_stories_should_be_reported_as_failing() throws Throwable {

// Given
SerenityStories failingStory = newStory("aFailingBehavior.story");

// When
run(failingStory);

// Then
List<TestOutcome> outcomes = loadTestOutcomes();
assertThat(outcomes.size(), is(1));
assertThat(outcomes.get(0).getResult(), is(TestResult.FAILURE));
}

@Test
public void should_not_reset_steps_for_each_scenario_if_configured() throws Throwable {

environmentVariables.setProperty("reset.steps.each.scenario", "false");
// Given
SerenityStories passingStory = newStory("aPassingBehaviorWithSeveralScenarios.story");

// When
run(passingStory);

// Then
List<TestOutcome> outcomes = loadTestOutcomes();
assertThat(outcomes.size(), is(2));
assertThat(outcomes.get(0).getResult(), is(TestResult.SUCCESS));
assertThat(outcomes.get(1).getResult(), is(TestResult.FAILURE));
}

@Test
public void variables_are_reset_between_steps_by_default() throws Throwable {

// Given
SerenityStories sharedVariablesStory = newStory("aBehaviorWithSharedVariables.story");

// When
run(sharedVariablesStory);

// Then
List<TestOutcome> outcomes = loadTestOutcomes();
assertThat(outcomes.size(), is(2));
assertThat(outcomes.get(0).getResult(), is(SUCCESS));
assertThat(outcomes.get(1).getResult(), is(FAILURE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package net.serenitybdd.jbehave;

import net.thucydides.core.model.TestOutcome;
import net.thucydides.core.model.TestResult;
import net.thucydides.core.util.EnvironmentVariables;
import org.junit.Test;

import java.util.List;

import static net.thucydides.core.matchers.PublicThucydidesMatchers.containsResults;
import static net.thucydides.core.model.TestResult.IGNORED;
import static net.thucydides.core.model.TestResult.PENDING;
import static net.thucydides.core.model.TestResult.SUCCESS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class WhenRunningJBehaveStoriesWithIgnored extends AbstractJBehaveStory {

final static class AStorySample extends SerenityStories {

public AStorySample(EnvironmentVariables environmentVariables) {
super(environmentVariables);
}

protected AStorySample(String storyName) {
findStoriesCalled(storyName);
}
}

private void runStories(SerenityStories stories) throws Throwable {
run(stories);
}

@Test
public void a_test_running_a_failing_story_should_not_fail_if_ignore_failures_in_stories_is_set_to_true() throws Throwable {

systemConfiguration.getEnvironmentVariables().setProperty("ignore.failures.in.stories", "true");
SerenityStories stories = new AFailingBehavior();
stories.setSystemConfiguration(systemConfiguration);
runStories(stories);
}

@Test
public void should_mark_scenarios_with_failing_assumption_as_skipped() throws Throwable {

// Given
SerenityStories stories = new ABehaviorWithAFailingAssumption(environmentVariables);

// When
run(stories);

// Then
List<TestOutcome> outcomes = loadTestOutcomes();
assertThat(outcomes.size(), is(2));
assertThat(outcomes.get(0).getResult(), is(IGNORED));
assertThat(outcomes.get(1).getResult(), is(SUCCESS));
}

@Test
public void stories_with_failing_assumptions_should_be_ignored() throws Throwable {

// Given
SerenityStories pendingStory = newStory("aBehaviorWithAFailingAssumption.story");

// When
run(pendingStory);

// Then
List<TestOutcome> outcomes = loadTestOutcomes();
assertThat(outcomes.get(0).getResult(), is(TestResult.IGNORED));
assertThat(outcomes.get(1).getResult(), is(TestResult.SUCCESS));
}
}
Loading

0 comments on commit 6e02df9

Please sign in to comment.