The Only Way to Test!

60
“The Only Way to Test!” Keith Pitty @keithpitty

description

Talk given to Sydney Ruby (a.k.a. rorosyd) on 8 July, 2014. Inspired by the discussions that ensued from DHH's provocative pronouncement that "TDD is Dead".

Transcript of The Only Way to Test!

Page 1: The Only Way to Test!

“The Only Way to Test!”

Keith Pitty !

@keithpitty

Page 2: The Only Way to Test!

Who’s telling you the right way to test?

Page 3: The Only Way to Test!
Page 4: The Only Way to Test!
Page 5: The Only Way to Test!
Page 6: The Only Way to Test!
Page 7: The Only Way to Test!
Page 8: The Only Way to Test!
Page 9: The Only Way to Test!
Page 10: The Only Way to Test!
Page 11: The Only Way to Test!
Page 12: The Only Way to Test!
Page 13: The Only Way to Test!
Page 14: The Only Way to Test!
Page 15: The Only Way to Test!
Page 16: The Only Way to Test!
Page 17: The Only Way to Test!
Page 18: The Only Way to Test!

So… who is right?

Page 19: The Only Way to Test!

Let’s engage our brains!

Page 20: The Only Way to Test!

What’s being posited?

Page 21: The Only Way to Test!
Page 22: The Only Way to Test!

James Coplien: “Why Most Unit Testing is Waste”

Comprehensive, well-argued article

Well worth reading with an open mind

May challenge your preconceptions

Page 23: The Only Way to Test!

James Coplien: “Why Most Unit Testing is Waste”

“Keep unit tests that test key algorithms for which there is a broad, formal, independent oracle of correctness, and for which there is ascribable business value.”

Page 24: The Only Way to Test!

James Coplien: “Why Most Unit Testing is Waste”

“Throw away tests that haven’t failed in a year.”

Page 25: The Only Way to Test!

James Coplien: “Why Most Unit Testing is Waste”

“Be humble about what tests can achieve. Tests don’t improve quality: developers do.”

Page 26: The Only Way to Test!
Page 27: The Only Way to Test!

Bob Martin: “Monogamous TDD”

argues that TDD does have significant value

Page 28: The Only Way to Test!

Bob Martin: “Monogamous TDD”

trustworthy, fast test suite

fearless, quick code cleaning

Page 29: The Only Way to Test!
Page 30: The Only Way to Test!

Gary Bernhardt: “TDD, Straw Men, and Rhetoric”

aims for test feedback in 300ms

Page 31: The Only Way to Test!

Gary Bernhardt: “TDD, Straw Men, and Rhetoric”

tests respond before he has time to think

Page 32: The Only Way to Test!

Gary Bernhardt: “TDD, Straw Men, and Rhetoric”

“TDD is useful and test isolation is useful, but they both involve making trade-offs.”

Page 33: The Only Way to Test!
Page 34: The Only Way to Test!

Corey Haines: “Speeding Up ActiveRecord Tests"

Specific suggestion to speed up ActiveRecord tests using his active_record_spec_helper

Page 35: The Only Way to Test!

Corey Haines: “Speeding Up ActiveRecord Tests"

Isolation: only include the parts of the system that are necessary

Page 36: The Only Way to Test!
Page 37: The Only Way to Test!

Martin Fowler, Kent Beck & DHH: “Is TDD Dead?”

Five discussions totally about three hours

Page 38: The Only Way to Test!

Martin Fowler, Kent Beck & DHH: “1. TDD and Confidence”

KB: TDD can, but does not necessarily, lead to flow

DHH: doesn’t like the conflation of TDD and confidence from self-testing code

MF: heavy mocking isn’t mandatory in TDD

Page 39: The Only Way to Test!

Martin Fowler, Kent Beck & DHH: “2. Test-induced design damage”

KB to DHH: “TDD isn’t taking you anywhere. You’re making the decisions.”

Page 40: The Only Way to Test!

Martin Fowler, Kent Beck & DHH: “3. Feedback and QA”

MF: categories of feedback:1. user needs 2. regression tests 3. healthy codebase

DHH: notion of criticality

KB: it’s a continuum and set of trade-offs

Page 41: The Only Way to Test!

Martin Fowler, Kent Beck & DHH: “3. Feedback and QA”

“As soon as you think you’re not making mistakes, you’re making mistakes.”

— Kent Beck

Page 42: The Only Way to Test!

Martin Fowler, Kent Beck & DHH: “4. Costs of Testing”

DHH: some tests are not justified

KB: delta coverage

MF: only test things that could possibly break

DHH: insufficient energy in refactoring

Page 43: The Only Way to Test!

Martin Fowler, Kent Beck & DHH: “5. Q & A; Summary”

KB: TDD helps problems to be broken down

MF: TDD with refactoring has often led to good design

DHH: “most people cannot leave good ideas the fuck alone”

Page 44: The Only Way to Test!

Martin Fowler, Kent Beck & DHH: “5. Summary”

KB: TDD is not dead but thanks for setting fire to it

DHH: TDD shouldn’t be mandated but we don’t want to lose self-testing code

MF: if you’re going to be involved in software development you have to be thoughtful

Page 45: The Only Way to Test!

What do I think?

Page 46: The Only Way to Test!

important to appreciate each other’s different

experiences

Page 47: The Only Way to Test!

I value TDD in some situations

Page 48: The Only Way to Test!

I also value other forms of feedback

Page 49: The Only Way to Test!

I sometimes write regression tests last

Page 50: The Only Way to Test!

I think it’s always important to consider how valuable a test is

Page 51: The Only Way to Test!

I know I still have a lot to learn

Page 52: The Only Way to Test!

What do you think?

Page 53: The Only Way to Test!

In summary…

Page 54: The Only Way to Test!

Learn from others

Page 55: The Only Way to Test!

Consider the context

Page 56: The Only Way to Test!

Think for yourself!

Page 57: The Only Way to Test!

References• http://david.heinemeierhansson.com/2014/tdd-is-dead-long-live-testing.html

• http://david.heinemeierhansson.com/2014/slow-database-test-fallacy.html

• http://www.rbcs-us.com/documents/Why-Most-Unit-Testing-is-Waste.pdf

• http://blog.8thlight.com/uncle-bob/2014/04/25/MonogamousTDD.html

• https://www.destroyallsoftware.com/blog/2014/tdd-straw-men-and-rhetoric

• http://articles.coreyhaines.com/posts/active-record-spec-helper/

• http://martinfowler.com/articles/is-tdd-dead/

Page 58: The Only Way to Test!

More References

• “Growing Object-Oriented Software, Guided by Tests”, Steve Freeman & Nat Price

• “Rails 4 Test Prescriptions: Build a Healthy Codebase”, Noel Rappin

• “Perfect Software and other illusions about testing”, Gerald M. Weinberg

Page 59: The Only Way to Test!

Thanks for listening

Page 60: The Only Way to Test!