Every test tells a story, but some tell a better story than others. Every test illustrates a specific path through the system to achieve a specific goal, but some paths are clearer than others. Valuable tests are the ones that both tell a compelling story, and can stand the test of time, providing value not only as acceptance tests but also as living documentation and easily maintainable regression tests.
In this session, John will invite you to come on a journey of discovery to learn how to write clean, clear and maintainable tests using the Journey Pattern, an innovative new approach to writing automated acceptance tests that are easier to understand, easier to extend and easier to maintain. You will also witness a demonstration of these principles in action, with live coding of Serenity BDD automated tests.
5. @JanMolak@wakaleo
How much are your tests worth?
Weekly cost
vs
weekly savings
$0
$20,000
$40,000
$60,000
$80,000
$100,000
$120,000
$140,000
$160,000
$180,000
1/09/2015 1/10/2015 1/11/2015 1/12/2015
Test0suite0cost0vs0savings0(per0week)
Cost0saved0par0week Test0suite0cost0per0week
Team cost is constant
Time saved increases with the
number of executed tests
6. @JanMolak@wakaleo
How much are your tests worth?
$0
$200,000
$400,000
$600,000
$800,000
$1,000,000
$1,200,000
1/09/2015 1/10/2015 1/11/2015 1/12/2015
What0is0your0test0suite0worth?
Test0suite0ROI Test0suite0cost
Cumulated cost
vs
cumulated savings
Cumulated value should increase
faster than cumulated cost
15. @JanMolak@wakaleo
Separation of Concerns - Layers
Goals
Tasks
Actions
What are you trying to achieve?
What do you need to do to achieve
this goal?
What interactions with the
system do you need for each
task?
17. @JanMolak@wakaleo
Separation of Concerns - Layers
Scenario: Add a new todo entry on the todo home page
Given I am on the Todo application home page
When I enter 'Buy some milk' into the New Todo field
And I press ENTER
Then the todo list box should contain 'Buy some milk'
18. @JanMolak@wakaleo
Separation of Concerns - Layers
Scenario: Add a new todo entry on the todo home page
Given I am on the Todo application home page
When I enter 'Buy some milk' into the New Todo field
And I press ENTER
Then the todo list box should contain 'Buy some milk'
Scenario: Record a new todo action for future use
Given I need to buy some milk
When I add the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in my todo list
23. @JanMolak@wakaleo
The Serenity layered architecture
Feature: Add new todos
James needs to be able to jot down actions he needs to do as he
thinks of them
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
A goal
A task
@Steps ATodoUser james;
@When(“^(?:.*) (?:adds|has added) the todo action '(.*)'$")
public void add_the_todo_action(String actionName) {
james.adds_an_action_called(actionName);
}
The task definition
TodoPage onTheTodoHomePage;
@Step
public void adds_an_action_called(String actionName) {
onTheTodoHomePage.addAnActionCalled(actionName);
}
An interaction
24. @JanMolak@wakaleo
Serenity for Living Documentation
Feature: Add new todos
I need to be able to jot down actions I need to do as fast as I think of them
Scenario: Record a new todo action for future use
Given I need to buy some milk
When I add the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in my todo list
30. @JanMolak@wakaleo
Origins of the Screenplay Pattern in Serenity
Antony Marcano
“Page Objects kinda suck. Why
not try this pattern instead?”
Agile Alliance Functional Test Tools Workshop 2007
2007
*
* Based on actual events
31. @JanMolak@wakaleo
Origins of the Screenplay Pattern in Serenity
Antony Marcano
2007 2009
More people should know
about this pattern
JNarrate
Andy Palmer
Let’s write a reference
implementation!
32. @JanMolak@wakaleo
Origins of the Screenplay Pattern in Serenity
Antony Marcano
2007 2009
“Coronation Street”
rocks
2012
Andy Palmer
Eureka! “Soap Opera Personas”
33. @JanMolak@wakaleo
Andy Palmer
Origins of the Screenplay Pattern in Serenity
Antony Marcano
2007 2009 2012
Jan Molak
You should call this “The
Journey Pattern”
Damn!
Why didn’t we
think of that!
34. @JanMolak@wakaleo
Andy
Palmer
Origins of the Screenplay Pattern in Serenity
Antony
Marcano
2007 2009 2012
Jan Molak
2015
John Smart
Serenity is cool
So let’s make it
happen!
But it needs the
Journey Pattern
35. @JanMolak@wakaleo
Andy
Palmer
Origins of the Screenplay Pattern in Serenity
Antony
Marcano
2007 2009 2012 2015
John Smart
Actually, the pattern has
evolved a lot
Jan Molak
Let’s call it the
‘Screenplay’ pattern
38. @JanMolak@wakaleo
I’d like to be able to recall all
the things I need to do
The Screenplay Pattern - A User-Centric model
Actors perform tasks
I’ll add ‘Buy some milk’ to my
todo list
39. @JanMolak@wakaleo
I’d like to be able to recall all
the things I need to do
The Screenplay Pattern - A User-Centric model
Actors may interact with the system to
perform these tasks
I’ll add ‘Buy some milk’ to my
todo list
Type ‘Buy the milk’
Press ‘ENTER’
40. @JanMolak@wakaleo
The Screenplay Pattern in Serenity
Actors have goals
Feature: Add new todos
James would like to be able to recall all the things he needs to do
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
I’d like to be able to recall all
the things I need to do
41. @JanMolak@wakaleo
A User-Centric model
Actors have abilities I can browse the web with my
browser
Actor james = Actor.named(“James");
@Managed
WebDriver hisBrowser;
…
james.can(BrowseTheWeb.with(hisBrowser));
42. @JanMolak@wakaleo
A User-Centric model
Actors perform tasks I’ll add ‘Buy some milk’ to my
todo list
@Steps
AddItem addATodoItem;
…
james.attemptsTo(addATodoItem.called("Buy some milk"));
43. @JanMolak@wakaleo
A User-Centric model
Actors perform tasks I’ll add ‘Buy some milk’ to my
todo list
@Steps
AddItem addATodoItem;
…
james.attemptsTo(addATodoItem.called("Buy some milk"));
actor.attemptsTo(
Enter.theValue(thingToDo).into(ToDoList.NEW_TODO_FIELD),
Hit.the(RETURN).keyIn(ToDoList.NEW_TODO_FIELD)
);
Type ‘Buy the milk’
Press ‘ENTER’
48. @wakaleo
Focus on the user
journey and a
common business
vocabulary
Scales well to
teams with varying
levels of experience
Good design
principles leading
to lower
maintenance costs
Code reuse within
and across teams
Key Benefits
50. @JanMolak@wakaleo
Want to learn more?
Ask us about training and mentoring
John Ferguson Smart
wakaleo
http://johnfergusonsmart.com
Jan Molak
http://janmolak.com
JanMolak