69

TDD: The Bad Parts

  • Upload
    pivotal

  • View
    460

  • Download
    0

Embed Size (px)

Citation preview

Page 1: TDD: The Bad Parts
Page 2: TDD: The Bad Parts

Matt Parker

@moonmaster9000

Page 3: TDD: The Bad Parts

TDD(the bad parts)

Page 4: TDD: The Bad Parts

BUT FIRST

A CAUTIONARY TALE

Page 5: TDD: The Bad Parts
Page 6: TDD: The Bad Parts
Page 7: TDD: The Bad Parts
Page 8: TDD: The Bad Parts
Page 9: TDD: The Bad Parts
Page 10: TDD: The Bad Parts
Page 11: TDD: The Bad Parts
Page 12: TDD: The Bad Parts
Page 13: TDD: The Bad Parts
Page 14: TDD: The Bad Parts
Page 15: TDD: The Bad Parts
Page 16: TDD: The Bad Parts
Page 17: TDD: The Bad Parts

WHY TDD?

Page 18: TDD: The Bad Parts

GO FAST FOREVER

Page 19: TDD: The Bad Parts

GO FAST FOREVER

CLEAN CODE

Page 20: TDD: The Bad Parts

GO FAST FOREVER

CLEAN CODE

REFACTORING

Page 21: TDD: The Bad Parts

GO FAST FOREVER

CLEAN CODE

REFACTORING

CONFIDENCE

Page 22: TDD: The Bad Parts

GO FAST FOREVER

CLEAN CODE

REFACTORING

CONFIDENCE

TESTS

Page 23: TDD: The Bad Parts

GO FAST FOREVER

CLEAN CODE

REFACTORING

CONFIDENCE

TESTS TDD

Page 24: TDD: The Bad Parts

PROBLEM #1:

OUTSIDE-IN BDD

Page 25: TDD: The Bad Parts
Page 26: TDD: The Bad Parts

1.Write acceptance test

2.Write controller test

3.Write model tests

Page 27: TDD: The Bad Parts

SLOW

Page 28: TDD: The Bad Parts

BRITTLE

Page 29: TDD: The Bad Parts

COUPLED

Page 30: TDD: The Bad Parts

FLAKY

Page 31: TDD: The Bad Parts
Page 32: TDD: The Bad Parts
Page 33: TDD: The Bad Parts

OUTSIDE?

Page 34: TDD: The Bad Parts

“Start at the outside

of what you want to

discover” - Joseph

Wilk

Page 35: TDD: The Bad Parts

OUTSIDE != GUI

Page 36: TDD: The Bad Parts

PROBLEM #2:

MOCKING

Page 37: TDD: The Bad Parts

@RequestMapping(value = "/translate", method = REQUEST.POST)

@ResponseBody

public String show(Model model, @RequestParam String word){

return translationService.translate(word);

}

Page 38: TDD: The Bad Parts

public void post_populatesModel() throws Exception {

TranslationService service = mock(TranslationService.class);

when(service.translate("apple")).thenReturn("appleway");

TranslatorController controller = new TranslatorController(service);

MockMvc mockMvc = standaloneSetup(controller).build();

mockMvc.perform(post("/translate").param("word", "apple"))

.andExpect(model().attribute("translation", "appleway"));}

}

Page 39: TDD: The Bad Parts

DUMMY

STUB

SPY

MOCK

-----------------------

FAKE

Page 40: TDD: The Bad Parts

THE LITTLE MOCKERblog.8thlight.com/uncle-bob/2014/05/14/TheLittleMocker.html

Page 41: TDD: The Bad Parts

S.O.L.I.D.● cleancoders.com

● Agile Software Development:

Principles, Patterns, and Practices

● Pivotal Labs

Page 42: TDD: The Bad Parts

HEXAGONAL TDDmoonmaster9000.github.io/hexagonal_tdd_in_ruby

Page 43: TDD: The Bad Parts

PROBLEM #3:

UNIT TESTING

Page 44: TDD: The Bad Parts

THREE LAWS OF

ROBOTICS TDD

Page 45: TDD: The Bad Parts

1. You are not allowed to

write any production code

unless it is to make a

failing unit test pass.

Page 46: TDD: The Bad Parts

2. You are not allowed to

write any more of a unit

test than is sufficient to

fail.

Page 47: TDD: The Bad Parts

3. You are not allowed to

write any more production

code than is sufficient to

pass the one failing unit

test.

Page 48: TDD: The Bad Parts

“Every class should be

paired with a well-

designed unit test”

Page 49: TDD: The Bad Parts

“Every public method

of every class should

be paired with a well-

designed unit test”

Page 50: TDD: The Bad Parts

class ClassOneTest {

@Test

public void publicMethodOne {

//...

}

@Test

public void publicMethodTwo {

//...

}

Page 51: TDD: The Bad Parts

ClassOne.java

ClassOneTest.java

ClassTwo.java

ClassTwoTest.java

Page 52: TDD: The Bad Parts

<REFACTORING>

Page 53: TDD: The Bad Parts

DESIGN PATTERN!

Page 54: TDD: The Bad Parts

class ClassOneTest {

@Test

public void publicMethodOne {

//MOVED SOME TESTS

}

//...

Page 55: TDD: The Bad Parts

class ClassThreeTest {

@Test

public void publicMethodOne {

//TESTS MOVED FROM ClassOneTest

}

//...

Page 56: TDD: The Bad Parts

ClassOne.java

ClassOneTest.java

ClassTwo.java

ClassTwoTest.java

ClassThree.java

ClassThreeTest.java

Page 57: TDD: The Bad Parts

TEST COUPLING

Page 58: TDD: The Bad Parts

DESIGN PATTERNS

Page 59: TDD: The Bad Parts

GO FAST FOREVER

CLEAN CODE

REFACTORING

CONFIDENCE

TESTS TDD

Page 60: TDD: The Bad Parts

GO FAST FOREVER

CLEAN CODE

REFACTORING

CONFIDENCE

TESTS TDD

Page 61: TDD: The Bad Parts

GO FAST FOREVER

CLEAN CODE

REFACTORING

CONFIDENCE

TESTS TDD

Page 62: TDD: The Bad Parts

“Every class should be

paired with a well-

designed unit test”

Page 63: TDD: The Bad Parts

“Every class should be

paired with a well-

designed unit test”

Page 64: TDD: The Bad Parts

“Every behavior should

be paired with a well-

designed unit test”

Page 65: TDD: The Bad Parts

MINIMIZE SURFACE

AREA

Page 66: TDD: The Bad Parts

So….

Page 67: TDD: The Bad Parts
Page 68: TDD: The Bad Parts

THANK YOU

Page 69: TDD: The Bad Parts

QUESTIONS?