Created
June 28, 2011 03:40
-
-
Save rhunter/1050443 to your computer and use it in GitHub Desktop.
JBehave example
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
import com.myob.liveaccounts.test.jbehave.StepBase; | |
import org.jbehave.core.model.ExamplesTable; | |
import org.jbehave.core.annotations.Given; | |
import org.jbehave.core.annotations.Then; | |
import org.jbehave.core.annotations.When; | |
import org.jbehave.core.annotations.Alias; | |
public class InvoiceSteps extends StepBase { | |
@Given("a JBehave story file called '$filename'") | |
public void givenStoryFile(String filename) { | |
// do stuff | |
} | |
@Given("I run the JUnit class '$classname'") | |
public void givenJUnitClass(String filename) { | |
// do stuff | |
} | |
@Given("step definitions scattered across several different files") | |
@Alias("step definitions") | |
public void givenStepDefinitions() { | |
// do stuff | |
} | |
@When("the team talk about the story") | |
public void talkAboutStory() { | |
// blah | |
} | |
@Then("members should understand parts depending on their focus: $table") | |
public void accountsShouldBalance(ExamplesTable table) { | |
List<Map<String, String>> rows = table.getRows(); | |
for (Map<String, String> row : rows) { | |
Person person = Person.focusedOn(row.get("Area of Focus")); | |
if (row.get("should understand story").equals("yes") { | |
assertThat(Person, canUnderstandStoryFile(storyFile)); | |
} | |
if (row.get("should understand step definitions").equals("yes") { | |
assertThat(Person, canUnderstandStepDefinitions()); | |
} | |
} | |
} | |
} | |
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
Story: As a domain expert | |
I want to write in a natural language | |
so that the whole team can talk about the same terms | |
It's generally helpful to understand what someone is talking about. | |
Scenario: Java and JBehave | |
JBehave combines plain-text story files with Java step definition classes | |
by way of a Java story class. | |
Given a JBehave story file called 'jbehave_example_story.story' | |
And I run the JUnit class 'JbehaveExampleStory' | |
And step definitions scattered across several different files | |
When the team talk about the story | |
Then members should understand parts depending on their focus: | |
| Area of focus | Should understand story | Should understand step definitions | | |
| business | yes | no | | |
| testing | yes | maybe | | |
| development | yes | yes | |
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
import org.jbehave.core.junit.JUnitStory; | |
public class JBehaveExampleStory extends JUnitStory { | |
@Override | |
public Configuration configuration() { | |
return new MostUsefulConfiguration() | |
.useStoryLoader(new LoadFromClasspath(this.getClass().getClassLoader())) | |
.useStoryReporterBuilder( | |
context.getBean("reportBuilder", ScreenCaptureStoryReporterBuilder.class).withDefaultFormats() | |
.withFormats(Format.CONSOLE, Format.HTML)) | |
.useParameterConverters(new ParameterConverters().addConverters(new AmountConverter())); | |
} | |
// the actual code (from which this was culled) overrides candidateSteps | |
// with SpringStepsFactory | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment