38
Powershell TDD Michael Willis

TDD in Powershell

Embed Size (px)

Citation preview

Page 1: TDD in Powershell

Powershell TDDMichael Willis

Page 2: TDD in Powershell

About

Following concept from https://laracasts.com/series/code-katas-in-php/episodes/2

This following is an except from a class presentation.

Page 3: TDD in Powershell

Test-Driven Development

1. Write a test case for some code that has yet to be implemented

2. Run the test case to verify it, which fails

3. Write only as much code as necessary to make the test pass

4. Run the test case

Page 4: TDD in Powershell

Roman Numeral Calculator

1 => I; Write the test; Watch it fail.

Page 5: TDD in Powershell

Simplest implementation to make it pass

Returning “I” brings us to “Green”

Page 6: TDD in Powershell

2 => II; Write Test; Watch it Fail

Page 7: TDD in Powershell

Strategies

Two simple ways to make this pass. We chose to use the second method.

Page 8: TDD in Powershell

5 => V; Write Test; Watch it Fail.

Page 9: TDD in Powershell

Make V=>5 Pass.

Page 10: TDD in Powershell

Add VI => 6 to Tests; Watch it fail

Page 11: TDD in Powershell

Refactoring to use a $solution variable.

Page 12: TDD in Powershell

Testing after Refactor; 6 still fails.

Page 13: TDD in Powershell

Remove the Else statement. Still Failing tests for 5 & 6.

Page 14: TDD in Powershell

Add minimal code to make test pass.

Page 15: TDD in Powershell

X => 10; Write Test; Watch it Fail.

Page 16: TDD in Powershell

Code duplication pattern becoming apparent

Page 17: TDD in Powershell

Write Test for 11=>XI

Test is already passing; Move on to next edge case.

Page 18: TDD in Powershell

20 => XX; Write Test; Watch it Fail.

Page 19: TDD in Powershell

Changing “if” to “while” lets this logic run twice for 20 making the test pass.

Page 20: TDD in Powershell

50 => L; Write Test; Watch it Fail.

Page 21: TDD in Powershell

Duplicate code shows us that we may have room for refactoring.

Page 22: TDD in Powershell

4 => IV; Write Test; Watch it Fail.

Page 23: TDD in Powershell

Make 4 Pass

Page 24: TDD in Powershell

Test for 9 is added.After 9 Fails we duplicate the code from 10 and change it to make 9 pass.

Page 25: TDD in Powershell

Refactor to pattern

Other if statements will also pass using a while statement.

Page 26: TDD in Powershell

Refactor (cont.)

The Statement

can be refactored to use a while loop as well.

Page 27: TDD in Powershell

Refactor

Duplicate code removed by using a lookup hashtable. Test by removing the: while “$Number -ge 50 loop.”

Tests still Green!

Page 28: TDD in Powershell

Remove >= 10 Loop; Fail since Lookup missing X.

Page 29: TDD in Powershell

Add 10 = “X” to lookup; Back to Green.

Page 30: TDD in Powershell

Remove all other while loops; Add Values to lookup.

Why is L Failing?

Page 31: TDD in Powershell

Hashtables are not sorted.

Page 32: TDD in Powershell
Page 33: TDD in Powershell

Missing Edge Cases

Page 34: TDD in Powershell

Back to Green!

Page 35: TDD in Powershell
Page 36: TDD in Powershell

Community Help

Team integration apps can help with on the fly code review / testing.

Page 37: TDD in Powershell

Almost forgot the sunflower

Page 38: TDD in Powershell