Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Powershell TDD
Michael Willis
About
Following concept from https://laracasts.com/series/code-katas-in-php/episodes/2
This following is an except from a ...
Test-Driven Development
1. Write a test case for some code that has yet to be implemented
2. Run the test case to verify i...
Roman Numeral Calculator
1 => I; Write the test; Watch it fail.
Simplest implementation to make it pass
Returning “I” brings us to “Green”
2 => II; Write Test; Watch it Fail
Strategies
Two simple ways to make this pass. We chose to use the second method.
5 => V; Write Test; Watch it Fail.
Make V=>5 Pass.
Add VI => 6 to Tests; Watch it fail
Refactoring to use a $solution variable.
Testing after Refactor; 6 still fails.
Remove the Else
statement. Still Failing tests
for 5 & 6.
Add minimal code to make test pass.
X => 10; Write Test; Watch it Fail.
Code duplication pattern
becoming apparent
Write Test for 11=>XI
Test is already passing; Move on to next edge case.
20 => XX; Write Test; Watch it Fail.
Changing “if” to “while”
lets this logic run twice
for 20 making the test
pass.
50 => L; Write Test; Watch it Fail.
Duplicate code shows
us that we may have
room for refactoring.
4 => IV; Write Test; Watch it Fail.
Make 4 Pass
Test for 9 is added.
After 9 Fails we duplicate the code
from 10 and change it to make 9 pass.
Refactor to pattern
Other if statements will also pass
using a while statement.
Refactor (cont.)
The Statement
can be refactored to use a while loop
as well.
Refactor
Duplicate code
removed by
using a lookup
hashtable. Test
by removing the:
while “$Number
-ge 50 loop.”
Tests stil...
Remove >= 10 Loop; Fail since Lookup missing X.
Add 10 = “X” to lookup; Back to Green.
Remove all other while loops; Add Values to lookup.
Why is L Failing?
Hashtables are not sorted.
Missing Edge Cases
Back to Green!
Community Help
Team integration apps can help with on the fly code review / testing.
Almost forgot the sunflower
TDD in Powershell
TDD in Powershell
TDD in Powershell
Upcoming SlideShare
Loading in …5
×

TDD in Powershell

387 views

Published on

Simple TDD workflow example using Powershell, Pester, and Slack. Original concept from Roman Numeral Kata by Jeffrey Way.

Published in: Technology
  • Login to see the comments

  • Be the first to like this

TDD in Powershell

  1. 1. Powershell TDD Michael Willis
  2. 2. About Following concept from https://laracasts.com/series/code-katas-in-php/episodes/2 This following is an except from a class presentation.
  3. 3. 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
  4. 4. Roman Numeral Calculator 1 => I; Write the test; Watch it fail.
  5. 5. Simplest implementation to make it pass Returning “I” brings us to “Green”
  6. 6. 2 => II; Write Test; Watch it Fail
  7. 7. Strategies Two simple ways to make this pass. We chose to use the second method.
  8. 8. 5 => V; Write Test; Watch it Fail.
  9. 9. Make V=>5 Pass.
  10. 10. Add VI => 6 to Tests; Watch it fail
  11. 11. Refactoring to use a $solution variable.
  12. 12. Testing after Refactor; 6 still fails.
  13. 13. Remove the Else statement. Still Failing tests for 5 & 6.
  14. 14. Add minimal code to make test pass.
  15. 15. X => 10; Write Test; Watch it Fail.
  16. 16. Code duplication pattern becoming apparent
  17. 17. Write Test for 11=>XI Test is already passing; Move on to next edge case.
  18. 18. 20 => XX; Write Test; Watch it Fail.
  19. 19. Changing “if” to “while” lets this logic run twice for 20 making the test pass.
  20. 20. 50 => L; Write Test; Watch it Fail.
  21. 21. Duplicate code shows us that we may have room for refactoring.
  22. 22. 4 => IV; Write Test; Watch it Fail.
  23. 23. Make 4 Pass
  24. 24. Test for 9 is added. After 9 Fails we duplicate the code from 10 and change it to make 9 pass.
  25. 25. Refactor to pattern Other if statements will also pass using a while statement.
  26. 26. Refactor (cont.) The Statement can be refactored to use a while loop as well.
  27. 27. Refactor Duplicate code removed by using a lookup hashtable. Test by removing the: while “$Number -ge 50 loop.” Tests still Green!
  28. 28. Remove >= 10 Loop; Fail since Lookup missing X.
  29. 29. Add 10 = “X” to lookup; Back to Green.
  30. 30. Remove all other while loops; Add Values to lookup. Why is L Failing?
  31. 31. Hashtables are not sorted.
  32. 32. Missing Edge Cases
  33. 33. Back to Green!
  34. 34. Community Help Team integration apps can help with on the fly code review / testing.
  35. 35. Almost forgot the sunflower

×