TDD All the Things!
-
Upload
liz-keogh -
Category
Leadership & Management
-
view
749 -
download
0
Transcript of TDD All the Things!
An Introduction to TDD
How to TDD People!
An Introduction to Cynefin
Refactoring People and Life
Test-Driven Experiments
public bool WaitFor(AutomationElementWrapper element, SomethingToWaitFor check, TimeSpan timeout, FailureToHappenHandler failureHandler, IEnumerable<AutomationEventWrapper> events) { Monitor.Enter(_waitingRoom); _triggeringEvent = null;
DateTime started = DateTime.Now; var handlerRemovers = AddPulsingHandlers(events, element);
bool checkPassed = true; while (!check(element, _triggeringEvent) && DateTime.Now.Subtract(started).CompareTo(timeout) < 0) { checkPassed = false; Monitor.Wait(_waitingRoom, timeout); } Monitor.Exit(_waitingRoom); ClearPulsingHandlers(handlerRemovers);
if (!checkPassed && !check(element, null)) { failureHandler(element); return false; } return true; }
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); }
// 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 eventvar 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)});
ShouldWaitForEventsToOccur
Given an automation elementWhen we cause a slow event on that elementAnd we wait for the eventThen we should be notified when the event occurs.
An Example of an Example
Given Fred has bought a microwaveAnd the microwave cost £100
When we refund the microwaveThen Fred should be refunded £100.
With Pixies!
Given Fred has bought a microwaveAnd the microwave cost £100
When we refund the microwaveThen Fred should be refunded £100.
Write afailingtest
Refactor
Existing behaviour
and anchorwhat you value!
Make it pass
New behaviour
Describedesired
behaviour
Changethe
behaviour
The sandwich model done right
Anchor what you value
Describe desired behaviour
THEN change the behaviour
(People can do this bit themselves!)
Estimating Complexity
5. Nobody has ever done it before4. Someone outside the org has done it before (probably a competitor)3. Someone in the company has done it before2. Someone in the team has done it before1. We all know how to do it.
Refactoring code
Make it run
Get the thing
that’s new working
Make it right
Make itfast
Separate concerns
so you can do more!
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.
Dan North’s “Three Ages”
ExploreOptimise for
Discovery
StabilizeOptimize forRepeatability
CommoditizeOptimize for
Efficiency
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 cando more!
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.
Horizon 2fights for budgetwith Horizon 1.
Focusing on strengthsfights for time
with the boring stuff.
Let’s TDD a people process(Thanks Tobias!)
Given my son’s room is a messWhen I ask him to clean it up
Then the room should be clean.
Well-formed outcomes
Given my son’s room is a messWhen I ask him to clean it up
Then the room should be clean.
I can see the carpet;
no clothes on the
floor; no toys on the
floor.
I look at it and say,
Wow!
A Naïve Scenario
CONTEXT EVENT OUTCOME
Well-formedoutcome
Event whichleadsto the
outcome
Reality.It’s all good,
right?
A Naïve Scenario
Given my son’s room is a messWhen I ask him to clean it up
Then the room should be clean.
Tom Gilb’s “Mafia Offer”
Given my son’s room is a messWhen I ask him to clean it up
Then the room should be cleanAnd he looks really miserable
and hates you?
Reality.It’s all good,
right?
Unwanted context
CONTEXT EVENT OUTCOME
Well-formedoutcome
Event whichleadsto the
outcome
UnwantedContext
UnwantedOutcome!
UnwantedContext
Subgoals
CONTEXT EVENT OUTCOME
Well-formedoutcome
Event whichleadsto the
outcome
Replacementcontext
UnwantedOutcome!
Given Scenario
CONTEXT EVENT OUTCOME
Well-formedoutcome
Event whichleadsto the
outcome
UnwantedContext
Replacementcontext
EVENT OUTCOME
Event whichleads to
replacement
Replacing the “Mafia Offer”
Given my son knowswhat “clean” looks like
And that it will make me say “Wow!”And be impressed with him
Given my son’s room is a messWhen I ask him to clean it up
Then the room should be cleanAnd he should be happy!
Changing reality
CONTEXT EVENT OUTCOME
Well-formedoutcome
Event whichleadsto the
outcome
UnwantedContext
Replacementcontext
EVENT
Event whichleadsto the
replacement
CONTEXT
Cynefin
Obvious
ComplicatedComplex
Chaotic
With thanks toDavid Snowden and Cognitive Edge
SenseCategorizeRespond
SenseAnalyzeRespond
ProbeSense
Respond
ActSense
Respond
A Safe-To-Fail Probe has…
A way of knowing it’s succeedingA way of knowing it’s failing
A way of dampening itA way of amplifying it
Coherence
Coherence
A reason for thinking thatthe probe might have
a positive impact
Can you think ofa scenario
in which this experimentsucceeds?
Success Scenarios
Given my client has a problemWhen I suggest a practice to help
Then they should be able to deliver software.
Success Scenarios
Given Fred has signed up for AppytasticWhen we sync to Facebook by default
Then Fred’s friends should seehow awesome Appytastic is!
Complementary Success Scenarios
Given Fred has signed up for AppytasticWhen we sync to Facebook by default
Then Fred should realise that Appytasticis a really easy way to get content
onto Facebook!
Conflicting Success Scenarios!
Given my client has a problemWhen I suggest a practice to help
Then it should help them to think ofdifferent practices
that really are helpful!
Failure Scenarios
Given my client has a problemAnd context I don’t know about
When I suggest a practice to helpThen they’ll think I’m an idiot.
Failure Scenarios
Given Fred has signed up for AppytasticWhen we sync to Facebook by default
Then Fred and Fred’s friendsmight see that Appytastic has
massive privacy issues.
A way of knowing it’s succeeding
My client delivers software.
Fred’s friends see how awesome Appytastic is (and sign up).
Success Metrics!
Software is delivered – how quickly?
Sign-up rate increases – how much does it increase by?
A way of knowing it’s failing
My client thinks I’m an idiot.
Fred and Fred’s friendsmight see that Appytastic has
massive privacy issues.
Failure metrics!
Frowning faces!(but you get what you measure,
so measure smiles)
Sign-up rate decreases;proportion of positive tweets decreases
What if our people
don’t have the
skills?
What ifthe 3rd party systemdoesn’t work that way?
What if someone
gives away
the admin
password?What if AWS fails?
What if the releasehas a bug in it?
What if a meteorhits our data centre?
A Safe-To-Fail Probe has…
A way of knowing it’s succeedingA way of knowing it’s failing
A way of dampening itA way of amplifying it
Coherence A way of avoiding failure completely
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.
Make it cheap to fail.
Given my client has a problemAnd context I don’t know about
When I suggest a practice to helpThen they’ll think I’m an idiot.
(Tell them it’s a way ofgetting context quickly.)
Make it cheap to fail
Given Fred has signed up for AppytasticWhen we sync to Facebook by default
Then Fred and Fred’s friendsmight see that Appytastic has
massive privacy issues!
(Put the flag on the server.)
Estimating Complexity
5. Nobody has ever done it before4. Someone outside the org has done it before (probably a competitor)3. Someone in the company has done it before2. Someone in the team has done it before1. We all know how to do it.
Familiarity5 4 3
2
1
Experts familiarwith scenariosUnfamiliar
scenarios
Familiarscenarios
Disaster movies!
Context Questioning
Is there a context which,for some event,
will give outcomes that arecheaper to change?
ScenariosAnchor the behaviour you value.
In unfamiliar scenarios, create options –make it safe-to-fail.
Change code;help people change themselves.
Some experimentsshould fail.