Transcript
Page 1: Transformation Priority Premise: TDD Test Order Matters

Transformation Priority Premise: TDD Test Order Matters

Mike Clement@mdclement

[email protected]://blog.softwareontheside.com

http://agilecodegames.com

Page 2: Transformation Priority Premise: TDD Test Order Matters

XP Simple Design

• Passes all tests• Clear, expressive, consistent• No duplication•Minimal

Page 3: Transformation Priority Premise: TDD Test Order Matters

TDD Review

TDD

• Red• Green• Refactor

Ways to get Green

• Fake it• Obvious

implementation• Triangulation

Page 4: Transformation Priority Premise: TDD Test Order Matters
Page 5: Transformation Priority Premise: TDD Test Order Matters
Page 6: Transformation Priority Premise: TDD Test Order Matters
Page 7: Transformation Priority Premise: TDD Test Order Matters

Example Transformations

• ({}–>nil) no code at all->code that employs nil• (nil->constant)• (variable->assignment) replacing the value of

a variable.• (statement->statements) adding more

unconditional statements.

Page 8: Transformation Priority Premise: TDD Test Order Matters

Uncle Bob’s Three Laws of TDD

• You are not allowed to write any production code unless it is to make a failing unit test pass.

• You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.

• You are not allowed to write any more production code than is sufficient to pass the one failing unit test.

Page 9: Transformation Priority Premise: TDD Test Order Matters

Rule of Perpetual

Inconsequence

Page 10: Transformation Priority Premise: TDD Test Order Matters

Proposed Transformations• ({}–>nil) no code at all->code that employs nil• (nil->constant)• (constant->constant+) a simple constant to a more complex constant• (constant->scalar) replacing a constant with a variable or an argument• (statement->statements) adding more unconditional statements.• (unconditional->if) splitting the execution path• (scalar->array)• (array->container)• (statement->recursion)• (if->while)• (expression->function) replacing an expression with a function or

algorithm• (variable->assignment) replacing the value of a variable.

Page 11: Transformation Priority Premise: TDD Test Order Matters

WORD WRAPA Fork in the Road

Page 12: Transformation Priority Premise: TDD Test Order Matters

Problem definition

• function named Wrap that takes two arguments, a string, and a column number

• The function returns the string, but with line breaks ('\n') inserted at just the right places to make sure that no line is longer than the column number.

• Try to break lines at word boundaries.

Page 13: Transformation Priority Premise: TDD Test Order Matters

LET’S CODE!

Page 14: Transformation Priority Premise: TDD Test Order Matters

?

Page 15: Transformation Priority Premise: TDD Test Order Matters

"I can't seem to get this test to pass without writing a lot

of untested code."

Page 16: Transformation Priority Premise: TDD Test Order Matters

They are the wrong tests, because you could not figure

out how to pass them.

Page 17: Transformation Priority Premise: TDD Test Order Matters

"[W]hen faced with a problem you do not

understand, do any part of it you do understand, then

look at it again."

Page 18: Transformation Priority Premise: TDD Test Order Matters

BACK UP!

Page 19: Transformation Priority Premise: TDD Test Order Matters

The Premise Applied

• Prefer higher priority transformations.• Choose tests that can be passed with higher

priority transformations.• When a low priority transformation seems

required, backtrack to see if there is a simpler test to pass.

Page 20: Transformation Priority Premise: TDD Test Order Matters

WHAT ABOUT SOLUTION QUALITY?Sorting Algorithms

Page 21: Transformation Priority Premise: TDD Test Order Matters

The Premise Applied

• Prefer higher priority transformations.• Choose tests that can be passed with higher

priority transformations.• When a low priority transformation seems

required, backtrack to see if there is a simpler test to pass.

Page 22: Transformation Priority Premise: TDD Test Order Matters

Proposed Prioritized Transformations

• ({}–>nil) no code at all->code that employs nil• (nil->constant)• (constant->constant+) a simple constant to a more complex constant• (constant->scalar) replacing a constant with a variable or an argument• (statement->statements) adding more unconditional statements.• (unconditional->if) splitting the execution path• (scalar->array)• (array->container)• (statement->recursion)• (if->while)• (expression->function) replacing an expression with a function or

algorithm• (variable->assignment) replacing the value of a variable.

Page 23: Transformation Priority Premise: TDD Test Order Matters

ABSOLUTE PRIORITY PREMISE“Cousin” Micah

Page 25: Transformation Priority Premise: TDD Test Order Matters

Software Craftsmanship!

• Participate in a local Software Craftsmanship group wherever home is for you.

Page 26: Transformation Priority Premise: TDD Test Order Matters

My Contact Info

• @mdclement• [email protected]• http://blog.softwareontheside.com• http://agilecodegames.com• Utah Software Craftsmanship Group– http://utahsc.org– @utahsc


Top Related