A fairly long talk which I did at BDD London, on using scenarios in different ways and for TDDing stuff which isn't code (people, lives, organizations, etc.)
6. public void ShouldWaitForEventsToOccur()
{
// Given an automation element
_window = LaunchPetShopWindow();
var combo = _window.Find<ComboBox>("petFoodInput");
// When we cause a slow event on that element
new Thread(() =>
{
Thread.Sleep(200);
combo.Select("PetFood[Carnivorous]");
}).Start();
// And we wait for the event
var eventOccurred = false;
new Waiter().WaitFor(
combo, (src, e) => {
eventOccurred = true;
return combo.Selection.Equals("PetFood[Carnivorous]");
},
new TimeSpan(0, 0, 1),
(ex) => Assert.Fail(),
new List<AutomationEventWrapper> {
new StructureChangeEvent(TreeScope.Element)});
// Then we should be notified when the event occurs
Assert.IsTrue(eventOccurred);
}
8. // Given an automation element
_window = LaunchPetShopWindow();
var combo =
_window.Find<ComboBox>("petFoodInput");
9. // When we cause a slow event on that element
new Thread(() =>
{
Thread.Sleep(200);
combo.Select("PetFood[Carnivorous]");
}).Start();
10. // And we wait for the event
var eventOccurred = false;
new Waiter().WaitFor(combo, (src, e) =>
{
eventOccurred = true;
return combo.Selection.Equals(
"PetFood[Carnivorous]");
}, new TimeSpan(0, 0, 1),
(ex) => Assert.Fail(),
new List<AutomationEventWrapper> {
new StructureChangeEvent(
TreeScope.Element)});
11. // Then we should be notified
// when the event occurs
Assert.IsTrue(eventOccurred);
19. An Example of an Example
Given Fred has bought a microwave
And the microwave cost £100
When we refund the microwave
Then Fred should be refunded £100.
20. With Pixies!
Given Fred has bought a microwave
And the microwave cost £100
When we refund the microwave
Then Fred should be refunded £100.
39. Estimating Complexity
5. Nobody has ever done it before
4. Someone outside the org has done it before
(probably a competitor)
3. Someone in the company has done it before
2. Someone in the team has done it before
1. We all know how to do it.
42. Refactoring code
Make it run
Get the thing
that’s new
working
Make it right
Make it
fast
Separate concerns
so you can
do more!
43. Good code
Focus on responsibilities and strengths
Is generous on input, strict on output
Is easy to understand and work with
You can trust clean code.
44. Dan North’s “Three Ages”
Explore
Optimise for
Discovery
Stabilize
Optimize for
Repeatability
Commoditize
Optimize for
Efficiency
47. Refactoring people
Try it out
Get the thing
that’s new
working
Focus on
strengths
Use others for
the boring
stuff!
Separate concerns
so you can
do more!
48.
49. Good people
Focus on responsibilities and strengths
Are generous in listening, honest in speaking
Are easy to understand and work with
You can trust good people.
50. Horizon 2
fights for budget
with Horizon 1.
Focusing on strengths
fights for time
with the boring stuff.
65. A Naïve Scenario
CONTEXT EVENT OUTCOME
Well-formed
outcome
Event which
leads
to the
outcome
Reality.
It’s all good,
right?
66. A Naïve Scenario
Given my son’s room is a mess
When I ask him to clean it up
Then the room should be clean.
67. Tom Gilb’s “Mafia Offer”
Given my son’s room is a mess
When I ask him to clean it up
Then the room should be clean
And he looks really miserable
and hates you?
68. Reality.
It’s all good,
right?
Unwanted context
CONTEXT EVENT OUTCOME
Well-formed
outcome
Event which
leads
to the
outcome
Unwanted
Context
Unwanted
Outcome!
70. Given Scenario
CONTEXT EVENT OUTCOME
Well-formed
outcome
Event which
leads
to the
outcome
Unwanted
Context
Replacement
context
EVENT OUTCOME
Event which
leads to
replacement
71. Replacing the “Mafia Offer”
Given my son knows
what “clean” looks like
And that it will make me say “Wow!”
And be impressed with him
Given my son’s room is a mess
When I ask him to clean it up
Then the room should be clean
And he should be happy!
72. Changing reality
CONTEXT EVENT OUTCOME
Well-formed
outcome
Event which
leads
to the
outcome
Unwanted
Context
Replacement
context
EVENT
Event which
leads
to the
replacement
CONTEXT
87. A Safe-To-Fail Probe has…
A way of knowing it’s succeeding
A way of knowing it’s failing
A way of dampening it
A way of amplifying it
Coherence
88. Coherence
A reason for thinking that
the probe might have
a positive impact
Can you think of
a scenario
in which this experiment
succeeds?
89. Success Scenarios
Given my client has a problem
When I suggest a practice to help
Then they should be able to deliver
software.
90. Success Scenarios
Given Fred has signed up for Appytastic
When we sync to Facebook by default
Then Fred’s friends should see
how awesome Appytastic is!
91. Complementary Success Scenarios
Given Fred has signed up for Appytastic
When we sync to Facebook by default
Then Fred should realise that Appytastic
is a really easy way to get content
onto Facebook!
92. Conflicting Success Scenarios!
Given my client has a problem
When I suggest a practice to help
Then it should help them to think of
different practices
that really are helpful!
93. Failure Scenarios
Given my client has a problem
And context I don’t know about
When I suggest a practice to help
Then they’ll think I’m an idiot.
94. Failure Scenarios
Given Fred has signed up for Appytastic
When we sync to Facebook by default
Then Fred and Fred’s friends
might see that Appytastic has
massive privacy issues.
95. A way of knowing it’s succeeding
My client delivers software.
Fred’s friends see how awesome
Appytastic is (and sign up).
100. A Safe-To-Fail Probe has…
A way of knowing it’s succeeding
A way of knowing it’s failing
A way of dampening it
A way of amplifying it
Coherence
A way of avoiding failure completely
101. Success is guaranteed…
…when you’ve done it before
…in the same context
…with the same requirements
…and the same people
…and the same technology
…and the same market
…and you own a time machine.
102. Make it cheap to fail.
Given my client has a problem
And context I don’t know about
When I suggest a practice to help
Then they’ll think I’m an idiot.
(Tell them it’s a way of
getting context quickly.)
103. Make it cheap to fail
Given Fred has signed up for Appytastic
When we sync to Facebook by default
Then Fred and Fred’s friends
might see that Appytastic has
massive privacy issues!
(Put the flag on the server.)
104. Estimating Complexity
5. Nobody has ever done it before
4. Someone outside the org has done it before
(probably a competitor)
3. Someone in the company has done it before
2. Someone in the team has done it before
1. We all know how to do it.
111. Scenarios
Anchor the behaviour you value.
In unfamiliar scenarios, create options –
make it safe-to-fail.
Change code;
help people change themselves.
Some experiments
should fail.