#gotocph @thejayfields @thejayfields JUnit version 4.11 ......... - - PowerPoint PPT Presentation

gotocph thejayfields thejayfields
SMART_READER_LITE
LIVE PREVIEW

#gotocph @thejayfields @thejayfields JUnit version 4.11 ......... - - PowerPoint PPT Presentation

#gotocph @thejayfields @thejayfields JUnit version 4.11 ......... @thejayfields JUnit version 4.11 .......................................................E.E.. @thejayfields JUnit version 4.11 .E.E.. There were 2 failures: 1)


slide-1
SLIDE 1

#gotocph @thejayfields

slide-2
SLIDE 2

JUnit version 4.11 .........

@thejayfields

slide-3
SLIDE 3

JUnit version 4.11 .......................................................E.E..

@thejayfields

slide-4
SLIDE 4

JUnit version 4.11 .E.E.. There were 2 failures: 1) statement(CustomerTest)

  • rg.junit.ComparisonFailure: expected:<...or John

Godfather 4[ ]9.0 Amount owed is 9...> but was:<...or John Godfather 4[ ]9.0 Amount owed is 9...> 2) htmlStatement(CustomerTest)

  • rg.junit.ComparisonFailure: expected:<...</h1>

<p>Godfather 4[ ]9.0</p> <p>Amount ow...> but was:<...</h1> <p>Godfather 4[ ]9.0</p> <p>Amount ow...> FAILURES!!! Tests run: 4, Failures: 2

@thejayfields

slide-5
SLIDE 5

JUnit version 4.11 .E.E.. There were 2 failures: 1) statement(CustomerTest)

  • rg.junit.ComparisonFailure: expected:<...or John

Godfather 4[ ]9.0 Amount owed is 9...> but was:<...or John Godfather 4[ ]9.0 Amount owed is 9...> 2) htmlStatement(CustomerTest)

  • rg.junit.ComparisonFailure: expected:<...</h1>

<p>Godfather 4[ ]9.0</p> <p>Amount ow...> but was:<...</h1> <p>Godfather 4[ ]9.0</p> <p>Amount ow...> FAILURES!!! Tests run: 4, Failures: 2

@thejayfields

slide-6
SLIDE 6

@thejayfields

slide-7
SLIDE 7

@thejayfields

slide-8
SLIDE 8

@thejayfields

slide-9
SLIDE 9

@thejayfields

slide-10
SLIDE 10

@thejayfields

slide-11
SLIDE 11

@thejayfields

slide-12
SLIDE 12

@thejayfields

slide-13
SLIDE 13

@thejayfields

slide-14
SLIDE 14

@thejayfields

slide-15
SLIDE 15

@thejayfields

slide-16
SLIDE 16

@thejayfields

slide-17
SLIDE 17

@thejayfields

slide-18
SLIDE 18

@thejayfields

slide-19
SLIDE 19

@thejayfields

slide-20
SLIDE 20

@thejayfields

slide-21
SLIDE 21

@thejayfields

slide-22
SLIDE 22

@thejayfields

slide-23
SLIDE 23

@thejayfields

slide-24
SLIDE 24

@thejayfields

slide-25
SLIDE 25

@thejayfields

slide-26
SLIDE 26

@thejayfields

slide-27
SLIDE 27
slide-28
SLIDE 28
  • 1. statement()
slide-29
SLIDE 29
  • 2. customer[]
slide-30
SLIDE 30
  • 3. Customer

Assignment

slide-31
SLIDE 31
  • 4. Digest setup
slide-32
SLIDE 32
  • 5. Object mother
slide-33
SLIDE 33
  • 6. OBJECT Mother

customer variations

slide-34
SLIDE 34
  • 7. expected

string building

slide-35
SLIDE 35
  • 8. rentalInfo()
slide-36
SLIDE 36
  • 9. rentalinfo

implemtation

slide-37
SLIDE 37
  • 10. find and

digest expstatement()

slide-38
SLIDE 38
slide-39
SLIDE 39

why?

@thejayfields

slide-40
SLIDE 40

we write tests we don’t need with time we don’t have to satisfy people we don’t like.

@thejayfields

slide-41
SLIDE 41
slide-42
SLIDE 42

To create a tiny universe where the software exists to do one thing and do it well.

  • - @delitescere

@thejayfields

slide-43
SLIDE 43

To create a tiny universe where the software exists to do one thing and do it well.

  • - @delitescere

@thejayfields

slide-44
SLIDE 44

motivators? enable refactoring, immediate feedback, and breaking a problem up into smaller pieces

@thejayfields

slide-45
SLIDE 45

motivators? enable refactoring, immediate feedback, and breaking a problem up into smaller pieces

@thejayfields

slide-46
SLIDE 46

motivators? enable refactoring, immediate feedback, and breaking a problem up into smaller pieces

@thejayfields

slide-47
SLIDE 47

motivators? enable refactoring, immediate feedback, and breaking a problem up into smaller pieces

@thejayfields

slide-48
SLIDE 48

motivators? enable refactoring, immediate feedback, and breaking a problem up into smaller pieces

@thejayfields

slide-49
SLIDE 49

motivators? enable refactoring, immediate feedback, and breaking a problem up into smaller pieces

@thejayfields

slide-50
SLIDE 50

DRY

@thejayfields

slide-51
SLIDE 51

Suite / Fixture / Test

@thejayfields

slide-52
SLIDE 52

Suite / Fixture / Test

@thejayfields

slide-53
SLIDE 53

Testing unrelated customers

slide-54
SLIDE 54

Creating unrelated customers

slide-55
SLIDE 55
  • verextracting
slide-56
SLIDE 56

relevant data

  • nly
slide-57
SLIDE 57
  • ne: replace loop with

individual tests

slide-58
SLIDE 58
slide-59
SLIDE 59
slide-60
SLIDE 60
slide-61
SLIDE 61

It’s only after we’ve duplicated everything that we’re free to dry anything

@thejayfields

slide-62
SLIDE 62

two: expect literals

@thejayfields

slide-63
SLIDE 63

@thejayfields

slide-64
SLIDE 64

@thejayfields

slide-65
SLIDE 65

three: inline setup

@thejayfields

slide-66
SLIDE 66

@thejayfields

slide-67
SLIDE 67

@thejayfields

slide-68
SLIDE 68
slide-69
SLIDE 69
slide-70
SLIDE 70

Motivators

@thejayfields

slide-71
SLIDE 71

validate the system feedback prevent regression

@thejayfields

slide-72
SLIDE 72

code coverage

@thejayfields

slide-73
SLIDE 73

enable refactoring

@thejayfields

slide-74
SLIDE 74

enable refactoring

@thejayfields

slide-75
SLIDE 75

document the system

@thejayfields

slide-76
SLIDE 76

manager told you to

@thejayfields

slide-77
SLIDE 77

tdd break up a problem improved design

@thejayfields

slide-78
SLIDE 78

customer acceptance

@thejayfields

slide-79
SLIDE 79
slide-80
SLIDE 80

Any fool can write a test that helps them today. Good programmers write tests that help the entire team in the future.

@thejayfields

slide-81
SLIDE 81

what can we do?

slide-82
SLIDE 82

This is your career and it’s ending one test suite run at a time

slide-83
SLIDE 83

a simple rule

  • 1. never cross boundaries
  • 2. the Class Under Test should be the
  • nly concrete class found in a test

@thejayfields

slide-84
SLIDE 84

two simple rules

  • 1. never cross boundaries
  • 2. the Class Under Test should be the
  • nly concrete class found in a test

@thejayfields

slide-85
SLIDE 85

@thejayfields

slide-86
SLIDE 86

@thejayfields

slide-87
SLIDE 87

@thejayfields

slide-88
SLIDE 88

@thejayfields

slide-89
SLIDE 89

@thejayfields

slide-90
SLIDE 90

Confidence

slide-91
SLIDE 91

isolation

slide-92
SLIDE 92

integration

slide-93
SLIDE 93

@thejayfields

slide-94
SLIDE 94

how else can I improve the test suite?

@thejayfields

slide-95
SLIDE 95

@thejayfields

slide-96
SLIDE 96

@thejayfields

slide-97
SLIDE 97

self destruction

slide-98
SLIDE 98

Our tests are failing us

slide-99
SLIDE 99

Poor SoluTion

  • r

Poor Solution

slide-100
SLIDE 100

Or?

slide-101
SLIDE 101

@thejayfields

slide-102
SLIDE 102

@thejayfields

slide-103
SLIDE 103

One Assertion per test

slide-104
SLIDE 104

wrapping up

@thejayfields

slide-105
SLIDE 105

The tests you own end up owning you.

@thejayfields

slide-106
SLIDE 106
slide-107
SLIDE 107

Your tests are not special. They are not beautiful or unique

  • snowflakes. They’re the same

decaying text as every other test.

@thejayfields

slide-108
SLIDE 108
slide-109
SLIDE 109

@thejayfields

Thank You. Questions?