29
Brandon Byars [email protected] TEST-DRIVEN DEVELOPMENT BEHAVIOR-DRIVEN DEVELOPMENT

Tdd and-bdd

Embed Size (px)

DESCRIPTION

Test driven development and behavior driven development

Citation preview

Page 1: Tdd and-bdd

Brandon Byars

[email protected]

TEST-DRIVEN DEVELOPMENTBEHAVIOR-DRIVEN DEVELOPMENT

Page 2: Tdd and-bdd

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

Page 3: Tdd and-bdd

Validate

Analyze

Design

Code

Test

Page 4: Tdd and-bdd

Time

Prod

uctiv

ityWHY TDD?

Immature practices

Our goal

Page 5: Tdd and-bdd

dS−− ≥ 0dt

Entropy: It’s the law

Page 6: Tdd and-bdd

Validate

Analyze

Design

Code

Test

Page 7: Tdd and-bdd

ValidateAnalyze Design Code Test

Page 8: Tdd and-bdd

ValidateAnalyze Design

Code

Test

INSIGHT #1: AUTOMATE TEST VERIFICATION

Page 9: Tdd and-bdd

[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"));

}

Page 10: Tdd and-bdd

ValidateAnalyze Design

Code

Test

INSIGHT #2: TEST FIRST

Page 11: Tdd and-bdd

ValidateAnalyze Design

Test

Code

INSIGHT #3: JUST ENOUGH CODE

Test

Page 12: Tdd and-bdd

[TestFixture]

public class StackTest

{

[Test]

public void NewStackShouldBeEmpty()

{

var stack = new Stack();

Assert.That(stack.IsEmpty());

}

}

Page 13: Tdd and-bdd

public class Stack

{

public bool IsEmpty()

{

return false;

}

}

Page 14: Tdd and-bdd

ValidateAnalyze

DesignTest

Code

INSIGHT #4: TDD IS A DESIGN TECHNIQUE

Test

Page 15: Tdd and-bdd

ValidateAnalyze

CodeTest

Design

INSIGHT #4: TDD IS A DESIGN TECHNIQUE

Test

Page 16: Tdd and-bdd

ValidateAnalyze

CodeTest

Design

INSIGHT #4: TDD IS A DESIGN TECHNIQUE

Test

Refactoring

Page 17: Tdd and-bdd

TDD is NOT:• A Testing Technique

TDD is:• A Design Technique

Page 18: Tdd and-bdd

EVOLUTIONARY DESIGN

Page 19: Tdd and-bdd
Page 20: Tdd and-bdd

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.”

-Antoine de Saint-Exupery

Page 21: Tdd and-bdd

Simple

Ain’t

Easy

Page 22: Tdd and-bdd

EVOLUTIONARY DESIGN

Simple Design Rules

1. Must pass all tests

2. Must communicate intent

3. No duplication

4. Use fewest possible (classes, methods…)

Page 23: Tdd and-bdd

BEHAVIOR DRIVEN DEVELOPMENT

There are only two hard problems in computer science:

• cache invalidation, and

• naming things.

-- Phil Karlton

Page 24: Tdd and-bdd

ValidateAnalyze

CodeTest

DesignTest

Page 25: Tdd and-bdd

ValidateAnalyze

CodeTest

Design Test

Specify

INSIGHT #5: TESTS AS COMMUNICATION

Page 26: Tdd and-bdd

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

Page 27: Tdd and-bdd

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()); }

Page 28: Tdd and-bdd

Time

Prod

uctiv

ityWHY NOT TDD?

We’ll never get here…

Our goal

Page 29: Tdd and-bdd

TIC TAC TOE

https://github.com/bbyars/TicTacToe