SlideShare a Scribd company logo
Unit Testing
Chris Jimenez
What is a Unit test?
Unit testing is testing of units in your code
base
“
The unit in question could be a Class
or a Method...
What is NOT a unit test???
◦ Developer Testing. Compiling
and running the application to
see if it does what you want it
to do is not unit testing.
What is NOT a unit test???
◦ Smoke/ Quality Testing. Running
an automated test that chugs
through a laundry list of
procedures involving large
sections of your code base is
not a unit test. This is the way
the QA department does
testing.
What is NOT a unit test???
◦ Things that involve databases,
files, web services, device
drivers or other things that are
external to your code. These are
called integration tests and they
test a lot more than just your
code.
“
The fact that something is
automated does not make it a unit
test
What is the purpose of Unit Testing?
Testing is, at its core,
experimentation. We’re just so
used to the hypothesis that our
code will work and that tests will
confirm that to be the case. Or
NOT!
What is the purpose of Unit Testing?
Testing at the unit level is about
running experiments on classes
and methods and capturing those
experiments and their results via
code.
What is the purpose of Unit Testing?
So unit testing is part of quality
assurance, but it isn’t itself quality
assurance, per se. Rather, it’s a
way of documenting and locking in
the behavior of the finest-grained
units of your code – classes – in
isolation.
What is the purpose of Unit Testing?
By understanding exactly how all
of the smallest units of your code
behave, it is straightforward to
assemble them predictably into
larger and larger components and
thus construct a well-designed
system.
Some Basic
Best Practices
and Definitions
Basic Principles
◦ Unit tests are just methods that
are decorated with annotations
(Java) or attributes (C#) to
indicate to the unit test runner
that they are unit tests. Each
method is generally a test.
◦ A unit test runner is simply a
program that executes
compiled test code and
provides feedback on the
results.
Basic Principles
◦ Tests will generally either pass
or fail, but they might also time
out or be inconclusive
◦ Tests will generally either pass
or fail, but they might also time
out or be inconclusive,
depending on the tooling that
you use.
Basic Principles
◦ Unit tests are simple and
localized. They should not
involve multi-threading, file I/ O,
database connections, web
services, etc. If you’re writing
these things, you’re not writing
unit tests but rather integration
tests.
Basic Principles
◦ Unit tests are fast. Your entire
unit test suite should execute in
seconds or quicker.
◦ Unit tests run in isolation, and
the order in which they’re run
should not matter at all. If test
one has to run before test two,
you’re not writing unit tests.
Basic Principles
◦ Unit tests should not involve
setting or depending on global
application state such as public,
static, stateful methods,
singletons, etc.
Arrange, Act,
Assert.
Or AAA
Arrange
What this means is that you start
off the test by setting up the class
instance in the state you want it
(usually by instantiating it and
then whatever else you want),
Act
Executing your test
Assert
Verify that what happened is what
you expected to happen.
Lets write our
first Unit Test
Unit testing
WOW
◦ Kind of a dense looking code
there…
◦ How do we know if this works?
◦ Run the entire application to see
if its blows up?
◦ But this is a pretty simple
method in a pretty simple class.
Doesn’t it seem like there ought
to be a way to make sure it
works?
But never fear
◦ Kind of a dense looking code
there…
◦ How do we know if this works?
◦ Run the entire application to see
if its blows up?
◦ But this is a pretty simple
method in a pretty simple class.
Doesn’t it seem like there ought
to be a way to make sure it
works?
But never fear
Why do we want to do this?
◦ Well, might be that you or
someone else later starts
playing around with the
implementation of IsPrime().
◦ Maybe you want to make it
faster.
◦ Maybe you realize it doesn’t
handle negative numbers
properly and aim to correct it.
◦ ETC!
Donts
Donts
◦ Units test are granular!
◦ If something fails, you dont
know what
Donts
◦ Units test are granular!
◦ If something fails, you dont
know what!
“
“Unit tests don’t just magically
spring up like mushrooms after a
few days of rain. They’re more like
roses – you have to plan for them
from the start and carefully
cultivate an environment in which
they can thrive.”
How to get started!
◦ Test New Classes Only
◦ Test Existing Code by Extracting
Little Classes
◦ Just do it!
Things that are hard to test
◦ Calls static methods.
(is that they manipulate some kind
of global state.)
◦ Invokes singletons .
◦ Dispatches background workers
◦ Accesses files, connects to
databases, calls web services,
etc.
◦ Has classes that require crazy
amounts of instantiation.
Things that are hard to test
◦ For now just stay away from all
of these...
Design New
Code for
Testability
Designs that are bad for testing
◦ Active Record
This architecture tightly couples
your database to your domain
logic and your domain logic to
the rules for navigating through
domain objects.
◦ WinForms / Webforms / Code
behind stuff
Monolithic Code
◦ Picture two methods. One is a
700-line juggernaut with more
control flow statements than
you can keep track of without a
spreadsheet. The other is five
lines long, consisting only of an
initialize statement, a foreach,
and a return statement. With
which would you rather work?
Procedural Code
Procedural Code
◦ Stay away from this sort of
Code
◦ Unit testing is about
deconstructing things into
smaller possible chunks
Procedural Code
◦ Stop thinking in when and start
thinking in what
◦ If you were thinking about
“what” first here, you would
form a much different mental
model of a person’s day. You’d
say things to yourself like, “well,
during the course of a person’s
day, he probably wakes up, gets
dressed, eats breakfast – well,
actually eats one or more meals
Other Design Considerations for Your
New Classes
◦ Avoid using fields to
communicate between your
methods by setting flags and
tracking state. Favor having
methods that can be executed
at any time and in any order.
◦ Don’t instantiate things in your
constructor. Favor passing them
in.
Other Design Considerations for Your
New Classes
◦ Similarly, don’t have a lot of
code or do a lot of work in your
constructor. This will make your
class painful to setup for test.
◦ In your methods, accept
parameters that are as
decomposed as possible. For
instance, don’t accept a
Customer object if all you do
with it is read its SSN property.
The earlier you
start writing
your unit tests,
the better.
Other examples
Other examples
Still dont want to Unit Test?
◦ Improve code quality
◦ Document the code
◦ Exercise Code
◦ Promote good design
◦ Help break problems into
manageable chunks
◦ Expose problems eairler
◦ Its cheaper to find problems
◦ Allow easier refactoring without
hesitation
Still dont want to Unit Test?
◦ Improve code quality
◦ Document the code
◦ Exercise Code
◦ Promote good design
◦ Help break problems into
manageable chunks
◦ Expose problems eairler
◦ Its cheaper to find problems
◦ Allow easier refactoring without
hesitation
Still dont want to Unit Test?
◦ Its easier to write code with unit
tests
Other considerations
◦ Name Your Tests Clearly and Be
Wordy
◦ Dont name your test like:
Test24, CustomerTest,
◦ Use:
◦ “Customer_IsValid_Returns_Fals
e_When_Customer_SocialSecur
ityNumber_Is_Empty”.
Other considerations
◦ Make your test suit fast. A good
test suit runs in seconds
◦ Test code is nice code
◦ Have a single assert per case
◦ Dont share states between your
test
◦ Encourage Others and Keep
Them Invested
References
◦ Michael Feathers “The Deep
Synergy Between Testability
and Good Design.” Video
◦ Starting to unit test, not as hard
as you think (Book)
◦ The art of unit test (Second
Edition) Book!
Thanks!
ANY QUESTIONS?

More Related Content

PPTX
A Brief Introduction to Test-Driven Development
Shawn Jones
 
PPT
Test driven-development
David Paluy
 
PPTX
Test-Driven Development In Action
Jon Kruger
 
PDF
Getting started with Test Driven Development
Ferdous Mahmud Shaon
 
PPTX
TDD Basics with Angular.js and Jasmine
Luis Sánchez Castellanos
 
PPTX
2016 10-04: tdd++: tdd made easier
Christian Hujer
 
PPTX
Roy Osherove TDD From Scratch
Roy Osherove
 
PDF
Test Driven Development
Dhaval Dalal
 
A Brief Introduction to Test-Driven Development
Shawn Jones
 
Test driven-development
David Paluy
 
Test-Driven Development In Action
Jon Kruger
 
Getting started with Test Driven Development
Ferdous Mahmud Shaon
 
TDD Basics with Angular.js and Jasmine
Luis Sánchez Castellanos
 
2016 10-04: tdd++: tdd made easier
Christian Hujer
 
Roy Osherove TDD From Scratch
Roy Osherove
 
Test Driven Development
Dhaval Dalal
 

What's hot (20)

PPTX
TDD - Test Driven Development
Tung Nguyen Thanh
 
PDF
A Not-So-Serious Introduction to Test Driven Development (TDD)
CodeOps Technologies LLP
 
PDF
Dependency Injection in iOS
Pablo Villar
 
PDF
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
PPTX
Test Driven Development (TDD) Preso 360|Flex 2010
guest5639fa9
 
PPT
Test Driven Development
Sachithra Gayan
 
PPTX
Unit Testing in Action - C#, NUnit, and Moq
XPDays
 
PPT
Getting Unstuck: Working with Legacy Code and Data
Cory Foy
 
PDF
Adding Unit Test To Legacy Code
Terry Yin
 
PPTX
Continuous Integration: Finding problems soonest
Shawn Jones
 
PDF
Test Driven Development (TDD)
David Ehringer
 
PPTX
Type mock isolator
MaslowB
 
PDF
Test Driven Development
Mireia Sangalo
 
ODP
@LinkingNote annotation in YATSPEC
Wojciech Bulaty
 
PPTX
Entaggle: an Agile Software Development Case Study
Elisabeth Hendrickson
 
PPTX
Test driven development
Nascenia IT
 
PPT
TDD (Test Driven Design)
nedirtv
 
PDF
TDD and BDD and ATDD
Anuar Nurmakanov
 
PDF
iOS Test-Driven Development
Pablo Villar
 
PDF
Common Challenges & Best Practices for TDD on iOS
Derek Lee
 
TDD - Test Driven Development
Tung Nguyen Thanh
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
CodeOps Technologies LLP
 
Dependency Injection in iOS
Pablo Villar
 
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Test Driven Development (TDD) Preso 360|Flex 2010
guest5639fa9
 
Test Driven Development
Sachithra Gayan
 
Unit Testing in Action - C#, NUnit, and Moq
XPDays
 
Getting Unstuck: Working with Legacy Code and Data
Cory Foy
 
Adding Unit Test To Legacy Code
Terry Yin
 
Continuous Integration: Finding problems soonest
Shawn Jones
 
Test Driven Development (TDD)
David Ehringer
 
Type mock isolator
MaslowB
 
Test Driven Development
Mireia Sangalo
 
@LinkingNote annotation in YATSPEC
Wojciech Bulaty
 
Entaggle: an Agile Software Development Case Study
Elisabeth Hendrickson
 
Test driven development
Nascenia IT
 
TDD (Test Driven Design)
nedirtv
 
TDD and BDD and ATDD
Anuar Nurmakanov
 
iOS Test-Driven Development
Pablo Villar
 
Common Challenges & Best Practices for TDD on iOS
Derek Lee
 
Ad

Viewers also liked (12)

PPTX
Deferred object
PiXeL16
 
PPTX
The Internet own boy
PiXeL16
 
PPTX
An introduction to Mobile Development (Spanish)
PiXeL16
 
PPTX
Indoor Positioning System with iBeacons
PiXeL16
 
PPTX
WWDC 2014
PiXeL16
 
PPTX
DevOps and Chef
PiXeL16
 
PPTX
iOS 7
PiXeL16
 
PPTX
REST with Eve and Python
PiXeL16
 
PPTX
WWDC 2016
PiXeL16
 
PPTX
Mobile architecture problems and solutions.
PiXeL16
 
PPTX
Hooked - How to build habit forming products
PiXeL16
 
PDF
Rest Introduction (Chris Jimenez)
PiXeL16
 
Deferred object
PiXeL16
 
The Internet own boy
PiXeL16
 
An introduction to Mobile Development (Spanish)
PiXeL16
 
Indoor Positioning System with iBeacons
PiXeL16
 
WWDC 2014
PiXeL16
 
DevOps and Chef
PiXeL16
 
iOS 7
PiXeL16
 
REST with Eve and Python
PiXeL16
 
WWDC 2016
PiXeL16
 
Mobile architecture problems and solutions.
PiXeL16
 
Hooked - How to build habit forming products
PiXeL16
 
Rest Introduction (Chris Jimenez)
PiXeL16
 
Ad

Similar to Unit testing (20)

PPTX
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
michael.labriola
 
PPTX
An Introduction to Unit Testing
Sahar Nofal
 
PPT
An insight to test driven development and unit testing
Dharmendra Prasad
 
PPTX
An Introduction To Software Development - Test Driven Development, Part 1
Blue Elephant Consulting
 
PPTX
TDD Best Practices
Attila Bertók
 
PPS
Why Unit Testingl
priya_trivedi
 
PPS
Why unit testingl
Priya Sharma
 
PPS
Why Unit Testingl
priya_trivedi
 
PPTX
An Introduction to unit testing
Steven Casey
 
PPTX
Test driven development
namkha87
 
PPTX
Unit Testing and TDD 2017
Xavi Hidalgo
 
PPS
Unit Testing
Anuj Arora
 
KEY
Driving application development through behavior driven development
Einar Ingebrigtsen
 
PDF
Testacular
James Ford
 
PDF
Unit testing (Exploring the other side as a tester)
Abhijeet Vaikar
 
PDF
5-Ways-to-Revolutionize-Your-Software-Testing
Mary Clemons
 
PDF
TDD Workshop UTN 2012
Facundo Farias
 
PDF
Unit testing - An introduction
Alejandro Claro Mosqueda
 
ODP
I Smell A RAT- Rapid Application Testing
Peter Presnell
 
PPTX
{10.0} Test Driven Development.pptx
AmalEldhose2
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
michael.labriola
 
An Introduction to Unit Testing
Sahar Nofal
 
An insight to test driven development and unit testing
Dharmendra Prasad
 
An Introduction To Software Development - Test Driven Development, Part 1
Blue Elephant Consulting
 
TDD Best Practices
Attila Bertók
 
Why Unit Testingl
priya_trivedi
 
Why unit testingl
Priya Sharma
 
Why Unit Testingl
priya_trivedi
 
An Introduction to unit testing
Steven Casey
 
Test driven development
namkha87
 
Unit Testing and TDD 2017
Xavi Hidalgo
 
Unit Testing
Anuj Arora
 
Driving application development through behavior driven development
Einar Ingebrigtsen
 
Testacular
James Ford
 
Unit testing (Exploring the other side as a tester)
Abhijeet Vaikar
 
5-Ways-to-Revolutionize-Your-Software-Testing
Mary Clemons
 
TDD Workshop UTN 2012
Facundo Farias
 
Unit testing - An introduction
Alejandro Claro Mosqueda
 
I Smell A RAT- Rapid Application Testing
Peter Presnell
 
{10.0} Test Driven Development.pptx
AmalEldhose2
 

Recently uploaded (20)

PDF
Immersive experiences: what Pharo users do!
ESUG
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
Immersive experiences: what Pharo users do!
ESUG
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Presentation about variables and constant.pptx
safalsingh810
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 

Unit testing

  • 2. What is a Unit test? Unit testing is testing of units in your code base
  • 3. “ The unit in question could be a Class or a Method...
  • 4. What is NOT a unit test??? ◦ Developer Testing. Compiling and running the application to see if it does what you want it to do is not unit testing.
  • 5. What is NOT a unit test??? ◦ Smoke/ Quality Testing. Running an automated test that chugs through a laundry list of procedures involving large sections of your code base is not a unit test. This is the way the QA department does testing.
  • 6. What is NOT a unit test??? ◦ Things that involve databases, files, web services, device drivers or other things that are external to your code. These are called integration tests and they test a lot more than just your code.
  • 7. “ The fact that something is automated does not make it a unit test
  • 8. What is the purpose of Unit Testing? Testing is, at its core, experimentation. We’re just so used to the hypothesis that our code will work and that tests will confirm that to be the case. Or NOT!
  • 9. What is the purpose of Unit Testing? Testing at the unit level is about running experiments on classes and methods and capturing those experiments and their results via code.
  • 10. What is the purpose of Unit Testing? So unit testing is part of quality assurance, but it isn’t itself quality assurance, per se. Rather, it’s a way of documenting and locking in the behavior of the finest-grained units of your code – classes – in isolation.
  • 11. What is the purpose of Unit Testing? By understanding exactly how all of the smallest units of your code behave, it is straightforward to assemble them predictably into larger and larger components and thus construct a well-designed system.
  • 13. Basic Principles ◦ Unit tests are just methods that are decorated with annotations (Java) or attributes (C#) to indicate to the unit test runner that they are unit tests. Each method is generally a test. ◦ A unit test runner is simply a program that executes compiled test code and provides feedback on the results.
  • 14. Basic Principles ◦ Tests will generally either pass or fail, but they might also time out or be inconclusive ◦ Tests will generally either pass or fail, but they might also time out or be inconclusive, depending on the tooling that you use.
  • 15. Basic Principles ◦ Unit tests are simple and localized. They should not involve multi-threading, file I/ O, database connections, web services, etc. If you’re writing these things, you’re not writing unit tests but rather integration tests.
  • 16. Basic Principles ◦ Unit tests are fast. Your entire unit test suite should execute in seconds or quicker. ◦ Unit tests run in isolation, and the order in which they’re run should not matter at all. If test one has to run before test two, you’re not writing unit tests.
  • 17. Basic Principles ◦ Unit tests should not involve setting or depending on global application state such as public, static, stateful methods, singletons, etc.
  • 19. Arrange What this means is that you start off the test by setting up the class instance in the state you want it (usually by instantiating it and then whatever else you want),
  • 21. Assert Verify that what happened is what you expected to happen.
  • 22. Lets write our first Unit Test
  • 24. WOW ◦ Kind of a dense looking code there… ◦ How do we know if this works? ◦ Run the entire application to see if its blows up? ◦ But this is a pretty simple method in a pretty simple class. Doesn’t it seem like there ought to be a way to make sure it works?
  • 25. But never fear ◦ Kind of a dense looking code there… ◦ How do we know if this works? ◦ Run the entire application to see if its blows up? ◦ But this is a pretty simple method in a pretty simple class. Doesn’t it seem like there ought to be a way to make sure it works?
  • 27. Why do we want to do this? ◦ Well, might be that you or someone else later starts playing around with the implementation of IsPrime(). ◦ Maybe you want to make it faster. ◦ Maybe you realize it doesn’t handle negative numbers properly and aim to correct it. ◦ ETC!
  • 28. Donts
  • 29. Donts ◦ Units test are granular! ◦ If something fails, you dont know what
  • 30. Donts ◦ Units test are granular! ◦ If something fails, you dont know what!
  • 31. “ “Unit tests don’t just magically spring up like mushrooms after a few days of rain. They’re more like roses – you have to plan for them from the start and carefully cultivate an environment in which they can thrive.”
  • 32. How to get started! ◦ Test New Classes Only ◦ Test Existing Code by Extracting Little Classes ◦ Just do it!
  • 33. Things that are hard to test ◦ Calls static methods. (is that they manipulate some kind of global state.) ◦ Invokes singletons . ◦ Dispatches background workers ◦ Accesses files, connects to databases, calls web services, etc. ◦ Has classes that require crazy amounts of instantiation.
  • 34. Things that are hard to test ◦ For now just stay away from all of these...
  • 36. Designs that are bad for testing ◦ Active Record This architecture tightly couples your database to your domain logic and your domain logic to the rules for navigating through domain objects. ◦ WinForms / Webforms / Code behind stuff
  • 37. Monolithic Code ◦ Picture two methods. One is a 700-line juggernaut with more control flow statements than you can keep track of without a spreadsheet. The other is five lines long, consisting only of an initialize statement, a foreach, and a return statement. With which would you rather work?
  • 39. Procedural Code ◦ Stay away from this sort of Code ◦ Unit testing is about deconstructing things into smaller possible chunks
  • 40. Procedural Code ◦ Stop thinking in when and start thinking in what ◦ If you were thinking about “what” first here, you would form a much different mental model of a person’s day. You’d say things to yourself like, “well, during the course of a person’s day, he probably wakes up, gets dressed, eats breakfast – well, actually eats one or more meals
  • 41. Other Design Considerations for Your New Classes ◦ Avoid using fields to communicate between your methods by setting flags and tracking state. Favor having methods that can be executed at any time and in any order. ◦ Don’t instantiate things in your constructor. Favor passing them in.
  • 42. Other Design Considerations for Your New Classes ◦ Similarly, don’t have a lot of code or do a lot of work in your constructor. This will make your class painful to setup for test. ◦ In your methods, accept parameters that are as decomposed as possible. For instance, don’t accept a Customer object if all you do with it is read its SSN property.
  • 43. The earlier you start writing your unit tests, the better.
  • 46. Still dont want to Unit Test? ◦ Improve code quality ◦ Document the code ◦ Exercise Code ◦ Promote good design ◦ Help break problems into manageable chunks ◦ Expose problems eairler ◦ Its cheaper to find problems ◦ Allow easier refactoring without hesitation
  • 47. Still dont want to Unit Test? ◦ Improve code quality ◦ Document the code ◦ Exercise Code ◦ Promote good design ◦ Help break problems into manageable chunks ◦ Expose problems eairler ◦ Its cheaper to find problems ◦ Allow easier refactoring without hesitation
  • 48. Still dont want to Unit Test? ◦ Its easier to write code with unit tests
  • 49. Other considerations ◦ Name Your Tests Clearly and Be Wordy ◦ Dont name your test like: Test24, CustomerTest, ◦ Use: ◦ “Customer_IsValid_Returns_Fals e_When_Customer_SocialSecur ityNumber_Is_Empty”.
  • 50. Other considerations ◦ Make your test suit fast. A good test suit runs in seconds ◦ Test code is nice code ◦ Have a single assert per case ◦ Dont share states between your test ◦ Encourage Others and Keep Them Invested
  • 51. References ◦ Michael Feathers “The Deep Synergy Between Testability and Good Design.” Video ◦ Starting to unit test, not as hard as you think (Book) ◦ The art of unit test (Second Edition) Book!