Upload
brandon-byars
View
952
Download
1
Embed Size (px)
DESCRIPTION
Test driven development and behavior driven development
Citation preview
As a software development organization,
I want to have more predictability and adaptability
So that I can respond to change
Given a new requirementWhen I write the code for itThen I want to know whether I did the right thing
Validate
Analyze
Design
Code
Test
Time
Prod
uctiv
ityWHY TDD?
Immature practices
Our goal
dS−− ≥ 0dt
Entropy: It’s the law
Validate
Analyze
Design
Code
Test
ValidateAnalyze Design Code Test
ValidateAnalyze Design
Code
Test
INSIGHT #1: AUTOMATE TEST VERIFICATION
[Test]
public void ShouldRouteToEchoAction()
{
var response = new HttpRequest("GET”,
"http://localhost/RestMvc/echo/hello"
).GetResponse();
Assert.That(response.StatusCode, Is.EqualTo(200));
Assert.That(response.Body, Is.EqualTo("hello"));
}
ValidateAnalyze Design
Code
Test
INSIGHT #2: TEST FIRST
ValidateAnalyze Design
Test
Code
INSIGHT #3: JUST ENOUGH CODE
Test
[TestFixture]
public class StackTest
{
[Test]
public void NewStackShouldBeEmpty()
{
var stack = new Stack();
Assert.That(stack.IsEmpty());
}
}
public class Stack
{
public bool IsEmpty()
{
return false;
}
}
ValidateAnalyze
DesignTest
Code
INSIGHT #4: TDD IS A DESIGN TECHNIQUE
Test
ValidateAnalyze
CodeTest
Design
INSIGHT #4: TDD IS A DESIGN TECHNIQUE
Test
ValidateAnalyze
CodeTest
Design
INSIGHT #4: TDD IS A DESIGN TECHNIQUE
Test
Refactoring
TDD is NOT:• A Testing Technique
TDD is:• A Design Technique
EVOLUTIONARY DESIGN
“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.”
-Antoine de Saint-Exupery
Simple
Ain’t
Easy
EVOLUTIONARY DESIGN
Simple Design Rules
1. Must pass all tests
2. Must communicate intent
3. No duplication
4. Use fewest possible (classes, methods…)
BEHAVIOR DRIVEN DEVELOPMENT
There are only two hard problems in computer science:
• cache invalidation, and
• naming things.
-- Phil Karlton
ValidateAnalyze
CodeTest
DesignTest
ValidateAnalyze
CodeTest
Design Test
Specify
INSIGHT #5: TESTS AS COMMUNICATION
As a software development organization,
I want to have more predictability and adaptability
So that I can respond to change
Given a new requirementWhen I write the code for itThen I want to know whether I did the right thing
private Requirement requirement;
[Given(“a new requirement”)]public void GivenANewRequirement(){ requirement = new Requirement(); }
[When(“I write the code for it”)]public void WhenIWriteTheCodeForIt(){ requirement.Satisfy(); }
[Then(“I want to know .*”)]public void ThenIWantToKnowIfItWorked(){ Assert.That(requirement.IsSatisfied()); }
Time
Prod
uctiv
ityWHY NOT TDD?
We’ll never get here…
Our goal
TIC TAC TOE
https://github.com/bbyars/TicTacToe