@LaylaCodesIt
@LaylaCodesIt
@LaylaCodesIt
MICROSOFTMVP


GITHUBSTAR


MK.NETORGANISER


C#LOVER


DEVELOPERADVOCATE@VMWARE


LAYLAPORTER
@LaylaCodesIt
WHYTDDANDTHETERMINATOR?
@LaylaCodesIt
TDDSUCCESSES
•Acceptance Criteria


•Focus


•Interfaces


•Asynchronous development


•Cleaner code


•Safe refactoring


•Fewer bugs


•Increasing returns


•Living documentation
@LaylaCodesIt
BACKTOTHETERMINATOR
@LaylaCodesIt
THEPROCESS
@LaylaCodesIt
GATHERTHEREQUIREMENTS
@LaylaCodesIt
@LaylaCodesIt
Terminator Requirements
Scan subjects and determine if they
require further investigation
Investigate subjects of interest and
determine if they are the target -
TERMINATE!
@LaylaCodesIt
Scan subjects and determine if
they require further investigation
@LaylaCodesIt
STARTWITHFAILINGTESTS
@LaylaCodesIt
When you write tests after coding you
may be writing them to fit your code
and not your requirements
@LaylaCodesIt
RED/GREENREFACTORPATTERN
• Write a failing test


• Write enough code to get the test to pass


• Refactor!
@LaylaCodesIt
OVERTOCODE
@LaylaCodesIt
REFACTOR!
@LaylaCodesIt
public
 
bool
 
InvestigateFurther(ISubject
 
subject)


{


 
 
 


 
 
 
 
if
 
(subject.SubjectName.ToLower()
 
=
=
 
"woman")


 
 
 
 
{


 
 
 
 
 
 
 
 
return
 
true;


 
 
 
 
}
 
 
 
 
 
 
 
 


 
 
 
 
if
 
(subject.SubjectName.ToLower()
 
=
=
 
"girl")


 
 
 
 
{


 
 
 
 
 
 
 
 
return
 
true;


 
 
 
 
}
 
 
 
 
 
 
 
 


 
 
 
 
if
 
(subject.SubjectName.ToLower()
 
=
=
 
"man")


 
 
 
 
{


 
 
 
 
 
 
 
 
return
 
true;


 
 
 
 
}
 
 
 
 
 
 
 
 


 
 
 
 
if
 
(subject.SubjectName.ToLower()
 
=
=
 
"boy")


 
 
 
 
{


 
 
 
 
 
 
 
 
return
 
true;


 
 
 
 
}
 
 
 
 
 
 
 
 


 
 
 
 
return
 
false;


}
@LaylaCodesIt
public
 
bool
 
InvestigateFurther(ISubject
 
subject)


{


 
 
 
 
switch
 
(subject.SubjectName.ToLower())


 
 
 
 
{


 
 
 
 
 
 
 
 
case
 
"woman":


 
 
 
 
 
 
 
 
case
 
"girl":


 
 
 
 
 
 
 
 
case
 
"man":


 
 
 
 
 
 
 
 
case
 
"boy":


 
 
 
 
 
 
 
 
 
 
 
 
return
 
true;


 
 
 
 
 
 
 
 
default:


 
 
 
 
 
 
 
 
 
 
 
 
return
 
false;


 
 
 
 
}


}


public
public
 
bool
 
InvestigateFurther(ISubject
 
subject)


{


 
 
 
 
switch
 
(subject.SubjectName.ToLower())


 
 
 
 
{


 
 
 
 
 
 
 
 
case
 
"woman":


 
 
 
 
 
 
 
 
case
 
"girl":


 
 
 
 
 
 
 
 
case
 
"man":


 
 
 
 
 
 
 
 
case
 
"boy":


 
 
 
 
 
 
 
 
 
 
 
 
return
 
true;


 
 
 
 
 
 
 
 
default:


 
 
 
 
 
 
 
 
 
 
 
 
return
 
false;


 
 
 
 
}


}


[TestCase("woman")]


[TestCase("girl")]


[TestCase("man")]


[TestCase("boy")]


public
 
void
 
TerminatorShould_Determine_ToInvestigate
Further


(string
 
subjectName)


{


 
 
 
 
var
 
subject
 
=
 
new
 
Subject
 
{SubjectName
 
=
 
subject
Name};


 
 
 
 
var
 
result
 
=
 
_sut.InvestigateFurther(subject);


 
 
 
 
result.Should().BeTrue();


}


[Test]
public
 
bool
 
InvestigateFurther(ISubject
 
subject)


{


 
 
 
 
switch
 
(subject.SubjectName.ToLower())


 
 
 
 
{


 
 
 
 
 
 
 
 
case
 
"woman":


 
 
 
 
 
 
 
 
case
 
"girl":


 
 
 
 
 
 
 
 
case
 
"man":


 
 
 
 
 
 
 
 
case
 
"boy":


 
 
 
 
 
 
 
 
 
 
 
 
return
 
true;


 
 
 
 
 
 
 
 
default:


 
 
 
 
 
 
 
 
 
 
 
 
return
 
false;


 
 
 
 
}


}


[TestCase("woman")]


public
 
void
 


TerminatorShould_DetermineNot_ToInvestigateFurther()


{


 
 
var
 
subject
 
=
 
new
 
Subject
 
{SubjectName
 
=
 
"T1000"};


 
 
var
 
result
 
=
 
_sut.InvestigateFurther(subject);


 
 
result.Should().BeFalse();


}
@LaylaCodesIt
WITHGOODPRACTICES,CODEMANAGEMENTBECOMESINFINITELYEASIER
@LaylaCodesIt
TDDFAILURES
•Underestimating the learning curve


•Confusing TDD with unit testing


•Thinking TDD is enough testing


•Not starting with failing tests


•Not refactoring enough


•Not actually doing TDD!
@LaylaCodesIt
IMPLEMENTATIONWITHINYOURORGANIZATION
•Can be controversial and is a significant culture change


•Initial drop in productivity can be disconcerting


•Productivity will go up and reworks reduced


•Increased understanding of requirements and their acceptance criteria
@LaylaCodesIt
IFYOUTAKEONETHINGAWAYFROMTHISTALK...
@LaylaCodesIt
[Test]


public void


TerminatorShould_Determine_ToInvestigateFurther


(ISubject subject)


{


var subject = new Subject{SubjectName = "woman"};


var result = _sut.InfestigateFurther(subject);


result.Should().BeTrue();


}
@LaylaCodesIt
[Test]


public void


TerminatorShould_Determine_ToInvestigateFurther


(ISubject subject)


{


var subject = new Subject{SubjectName = "woman"};


var result = _sut.InfestigateFurther(subject);


result.Should().BeTrue();


}


public bool _sut.InvestigateFurther(ISubject subject)


{


return true;


}
@LaylaCodesIt
[Test]


public void


TerminatorShould_Determine_ToInvestigateFurther


(ISubject subject)


{


var subject = new Subject{SubjectName = "woman"};


var result = _sut.InfestigateFurther(subject);


result.Should().BeTrue();


}


public bool _sut.InvestigateFurther(ISubject subject)


{


return true;


}


Write the least amount
of code to get your test
to pass.
Return true!
@LaylaCodesIt
Twitter:@LaylaCodesIt


GitHub:Layla-P


Email:laylap@vmware.com
Repo:http://bit.ly/tdd-terminator


Deck:http://bit.ly/tdd-deck


Twitch:twitch.tv/LaylaCodesIt


Yaks:https://bit.ly/shaving-a-yak

TDD and the Terminator: An Introduction to Test-Driven Development