SlideShare a Scribd company logo
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 class presentation.
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
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 still Green!
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.
TDD in Powershell
Missing Edge Cases
Back to Green!
TDD in Powershell
Community Help
Team integration apps can help with on the fly code review / testing.
Almost forgot the sunflower
TDD in Powershell

More Related Content

PPT
Kelompok 8 Pbw
PPT
Kelompok 8 Pbw
PDF
selection structures
PPTX
PDF
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
PDF
csharp repitition structures
PPTX
Loops in C Programming Language
Kelompok 8 Pbw
Kelompok 8 Pbw
selection structures
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
csharp repitition structures
Loops in C Programming Language

What's hot (20)

PDF
Python Flow Control
PPTX
Loops c++
PPTX
Types of loops in c language
PPT
Different loops in C
PPT
Looping statements in Java
PDF
Control statements
PPTX
Loops in c
PDF
Reconciling Functional Programming and Exceptions
PPT
Control structure C++
DOC
Jumping statements
PPTX
Loops in c language
PPTX
10control statement in c#
PPT
C++ chapter 4
PPTX
Comp ppt (1)
PPTX
Understand Decision structures in c++ (cplusplus)
PPTX
Control structures in java
PPTX
C++ loop
PDF
escape sequences and substitution markers
PPT
Looping in c++
Python Flow Control
Loops c++
Types of loops in c language
Different loops in C
Looping statements in Java
Control statements
Loops in c
Reconciling Functional Programming and Exceptions
Control structure C++
Jumping statements
Loops in c language
10control statement in c#
C++ chapter 4
Comp ppt (1)
Understand Decision structures in c++ (cplusplus)
Control structures in java
C++ loop
escape sequences and substitution markers
Looping in c++
Ad

Similar to TDD in Powershell (20)

PDF
TDD Flow: The Mantra in Action
PDF
Unit testing - A&BP CC
PDF
Test driven development
PDF
SE2_Lec 21_ TDD and Junit
DOCX
CPSC 120Spring 2014Lab 5Name _____________________.docx
PDF
TDD reloaded - JUGTAA 24 Ottobre 2012
DOCX
CMIS 102 Entire Course NEW
PDF
Test Driven Development
PDF
Presentation slides: "How to get 100% code coverage"
PPTX
SE2018_Lec 20_ Test-Driven Development (TDD)
PDF
Test Driven Development
PDF
IntroTestMore
PDF
IntroTestMore
PPT
PDF
Bdd for-dso-1227123516572504-8
PPT
Test Presentation
KEY
Tdd for BT E2E test community
ODP
TDD in PHP - Memphis PHP 2011-08-25
TDD Flow: The Mantra in Action
Unit testing - A&BP CC
Test driven development
SE2_Lec 21_ TDD and Junit
CPSC 120Spring 2014Lab 5Name _____________________.docx
TDD reloaded - JUGTAA 24 Ottobre 2012
CMIS 102 Entire Course NEW
Test Driven Development
Presentation slides: "How to get 100% code coverage"
SE2018_Lec 20_ Test-Driven Development (TDD)
Test Driven Development
IntroTestMore
IntroTestMore
Bdd for-dso-1227123516572504-8
Test Presentation
Tdd for BT E2E test community
TDD in PHP - Memphis PHP 2011-08-25
Ad

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Approach and Philosophy of On baking technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Mobile App Security Testing_ A Comprehensive Guide.pdf
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation_ Review paper, used for researhc scholars
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Chapter 3 Spatial Domain Image Processing.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
sap open course for s4hana steps from ECC to s4
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

TDD in Powershell