A quick guide to Behavior Driven Development and achieving
Eclipse test automation
Ankur Sharma
Opentext
BDD
• BDD is a second-generation, outside-in, pull-based, multiple-
stakeholder, multiple-scale, high-automation, agile methodology. It
describes a cycle of interactions with well-defined outputs, resulting
in the delivery of working, tested software that matters.
BDD
• BDD is a second-generation, outside-in, pull-based, multiple-
stakeholder, multiple-scale, high-automation, agile methodology. It
describes a cycle of interactions with well-defined outputs, resulting
in the delivery of working, tested software that matters.
• TDD technique
• define a test set for the unit first;
• make the tests fail;
• then implement the unit;
• finally verify that the implementation of the unit makes the tests succeed.
BDD
• TDD technique
• define a test set for the unit first;
• make the tests fail;
• then implement the unit;
• finally verify that the implementation of the unit makes the tests succeed.
• Do we really follow it?
• Of course NOT
BDD
Focus on:
• Where to start in the process
• What to test and what not to test
• How much to test in one go
• What to call the tests
• How to understand why a test fails
Story: Returns go to stock
As a store owner
In order to keep track of stock
I want to add items back to stock when they're returned.
Scenario 1: Refunded items should be returned to stock
Given that a customer previously bought a black sweater from me
And I have three black sweaters in stock.
When they return the black sweater for a refund
Then I should have four black sweaters in stock.
Scenario 2: Replaced items should be returned to stock
Given that a customer previously bought a blue garment from me
And I have two blue garments in stock
And three black garments in stock.
When they return the blue garment for a replacement in black
Then I should have three blue garments in stock
And two black garments in stock.
Test Case
JBehave
• BDD Framework
• Pure Java implementation
• Elaborate support for Stories
• Grammar
• Annotations
• Reporting
• Eclipse Integration
• CI Support through Ant/Maven
Story
Code
Story to Code
Annotations
Annotations
@Given
@When
@Then
@Alias
@Pending
@BeforeScenario
@AfterScenario
@BeforeStory
@AfterStory
…
Execution
<taskdef name="runStoriesAsEmbeddables"
classname="org.jbehave.ant.RunStoriesAsEmbeddables"
classpathref="your.runtime.classpath"/>
<runStoriesAsEmbeddables
includes="**/*Stories.java"
metaFilters="+author *,-skip"
systemProperties="java.awt.headless=true"
ignoreFailureInStories="true"
ignoreFailureInView="false"
generateViewAfterStories="true"/>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>[version]</version>
<executions>
<execution>
<id>run-stories-as-embeddables</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/*Stories.java</include>
</includes>
<metaFilters>
<metaFilter>+author *</metaFilter>
<metaFilter>-skip</metaFilter>
</metaFilters>
<systemProperties>
<property>
<name>java.awt.headless</name>
<value>true</value>
</property>
</systemProperties>
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>false</ignoreFailureInView>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
How Eclipse fits in here?
Eclipse
RCP
Applications
SWTBot
RCP
Automation
JBehave
Story
execution
SWTBot
Scenario Testing Java 11 Support
Given A Java project with name MyJavaProject
When Java project JDK Complaince is set to 11
Then There are no compilation errors
@Given(“A Java project with name $ProjectName)
@Test
public void canCreateANewJavaProject(String projectName) throws
Exception {
bot.menu("File").menu("New").menu("Project...").click();
SWTBotShell shell = bot.shell("New Project");
shell.activate();
bot.tree().expandNode("Java").select("Java Project");
bot.button("Next >").click();
bot.textWithLabel("Project name:").setText(projectName );
bot.button("Finish").click();
}
Take Away
• True Agile, BDD, TDD, etc is not seen in real life
• Bake a solution that works for your product
• Automate
• Automate
• Automate
• CI is a way of life now
Thanks
Given Presentation is over
When Time for Q&A
Then Take the questions

Please Behave Yourself: BDD and automating Eclipse RCP applications using JBehave - Ankur Sharma