SlideShare a Scribd company logo
Win at Life
  with Unit Testing.
   by Mark Story
Who is this goofball

Art college graduate that needed to make
money.

CakePHP core contributor for 2.5 years.
Developer of DebugKit, ApiGenerator and
several other plugins.

Lead front end developer at FreshBooks
Can unit testing
   make me
  awesome?
Hell yes.
Why write tests?

Helps ensure things that did work, still do.
Helps reduce time it takes to fix new
defects.
Helps you plan a design, showing you
where it might be complicated or overly
coupled.
Living documentation.
...


Catch issues earlier.
Increased developer confidence.
Automated killer robots.
What to test?

Code that keeps you up at night.
Code that involves real money.
Code that has broken before.
Code that is tedious to test manually.
Different flava’s


Unit tests
Functional or Integration tests
Unit Tests

Testing the smallest parts of your
application in isolation.
Often testing single methods or single
functions.
Generally uses many mocks.
Really useful when doing Test driven
development.
Functional Tests

Tests pieces working well together.
Test top level objects to ensure all their guts
are working together.
Tests hitting database fixtures are often
functional tests.
Functional tests run slower, but use more
active code.
Challenges of testing

 Time. It takes time to write tests. But it
 takes more time to fix the same bugs later
 multiple times.
 Only shows the presence of issues, not the
 absence.
 Only catches errors you have tests for.
Benefits of testing

Find problems earlier.
Can be automated, robots are helpful.
Less manual testing.
Easier to ensure requirements are met.
Unicorns.
The End.
Of the part where I extol the winsauce tests
                can bring.
Mock objects
<insert>A funny joke</insert>
Mocks and test
      doubles
Writing isolated tests is hard. Mock objects
make it easier.
Mocks help ensure your objects are
touching other objects in the right places.
Mocks help you stub out behaviour before
you write the real deal.
Can I use a mock
       for:
     Global functions?
   Stuff not in functions?
No.
When to use mocks

When talking to the outside world.
  Email.
  Webservices (Twitter, Paypal, YouTube).
  Writing files to disk.
  Writing to the database.
...


When you want to ensure two objects are
working together properly.
When you do want to isolate problems.
Mocking your code

Make sure dependencies can be replaced at
runtime.
 Constructor injection.
 Factory methods.
 Setter methods.
Constructor Injection

 Accept objects your object depends on in
 the constructor.
 Jam mocks in when testing.
Factory Factory
      Factory
Factory methods can be overridden in
subclasses to return mocks.
Setter method
Allows post construction modification of
internal dependencies.
Mocks in the house


Mocks can be critical of a test subject.
Mocks and stub out dangerous
components, or methods.
Critical mocking
Critic mocks check that other objects touch
them correctly.
Stub danger.
You can stub methods that send headers or
touch the outside world.
Stub expensive stuff.
 Mocks can be used to stub network
 resources or expensive to fetch results.
In conclusion


Mocks help make tests run faster, and
require less setup & teardown.
They allow you to write true unit tests.
The End.
(of the part where I blabber about mocks)
Automated Killer
    Robots
 test automation for squishy humans.
Automated testing.


Tests that are never run, are as good as
deleted.
Build servers to the rescue!
Hudson

Hudson is a continuous integration server
built in Java.
Has a great plugin community.
Can send emails, Jabber and give pithy
Chuck Norris quotes.
...


Can be configured to run on a schedule or
post commit.
Integrates well with SVN and there is a GIT
plugin too.
Typical Hudson setup

 Run tests on each commit/push.
 Run all tests again each night, incase there
 was a slow day.
 Nightly builds are also a good time to run
 code coverage builds.
Setting Hudson up


Go to http://hudson-ci.org
wget http://hudson-ci.org/latest/hudson.war

java -jar hudson.war
Hudson dashboard
Hudson dashboard
Hudson dashboard
Hudson dashboard
Hudson project
The End.
For real this time.
Questions?

More Related Content

What's hot

Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven development
toteb5
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
Shawn Jones
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sergey Aganezov
 
Test automation
Test automationTest automation
Test automation
Xavier Yin
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
Pablo Villar
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Mireia Sangalo
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
nedirtv
 
DIG1108C Lesson 7 Fall 2014
DIG1108C Lesson 7 Fall 2014DIG1108C Lesson 7 Fall 2014
DIG1108C Lesson 7 Fall 2014
David Wolfpaw
 
Behaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlowBehaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlow
Pascal Laurin
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
Rachid Kherrazi
 
Quality Assurance Guidelines
Quality Assurance GuidelinesQuality Assurance Guidelines
Quality Assurance Guidelines
Tim Stribos
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sachithra Gayan
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
L&T Technology Services Limited
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
Vitaliy Kulikov
 
TDD- Test Driven Development
TDD- Test Driven DevelopmentTDD- Test Driven Development
TDD- Test Driven Development
Liza Antoun
 
Testing JavaScript Applications
Testing JavaScript ApplicationsTesting JavaScript Applications
Testing JavaScript Applications
Muhammad Samu
 
Unit Testing Your Application
Unit Testing Your ApplicationUnit Testing Your Application
Unit Testing Your Application
Paladin Web Services
 
Code review process with JetBrains UpSource
Code review process with JetBrains UpSourceCode review process with JetBrains UpSource
Code review process with JetBrains UpSource
Oleksii Prohonnyi
 
Acceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And FriendsAcceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And Friends
Christopher Bartling
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
Naresh Jain
 

What's hot (20)

Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven development
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test automation
Test automationTest automation
Test automation
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
DIG1108C Lesson 7 Fall 2014
DIG1108C Lesson 7 Fall 2014DIG1108C Lesson 7 Fall 2014
DIG1108C Lesson 7 Fall 2014
 
Behaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlowBehaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlow
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
 
Quality Assurance Guidelines
Quality Assurance GuidelinesQuality Assurance Guidelines
Quality Assurance Guidelines
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
 
TDD- Test Driven Development
TDD- Test Driven DevelopmentTDD- Test Driven Development
TDD- Test Driven Development
 
Testing JavaScript Applications
Testing JavaScript ApplicationsTesting JavaScript Applications
Testing JavaScript Applications
 
Unit Testing Your Application
Unit Testing Your ApplicationUnit Testing Your Application
Unit Testing Your Application
 
Code review process with JetBrains UpSource
Code review process with JetBrains UpSourceCode review process with JetBrains UpSource
Code review process with JetBrains UpSource
 
Acceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And FriendsAcceptance Test Driven Development With Spec Flow And Friends
Acceptance Test Driven Development With Spec Flow And Friends
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 

Viewers also liked

Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
Richard Paul
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
alessiopace
 
Best practices unit testing
Best practices unit testing Best practices unit testing
Best practices unit testing
Tricode (part of Dept)
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
Shaun Abram
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
nickokiss
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
suhasreddy1
 

Viewers also liked (8)

Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
Best practices unit testing
Best practices unit testing Best practices unit testing
Best practices unit testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 

Similar to Win at life with unit testing

assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
michael.labriola
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
Facundo Farias
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
michael.labriola
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
Jon Kruger
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
dunglinh111
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk
 
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsIntegration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Rody Middelkoop
 
Test driven development
Test driven developmentTest driven development
Test driven development
namkha87
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
Attila Bertók
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
Eric Selje
 
Testing 101
Testing 101Testing 101
Testing 101
Noam Barkai
 
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
DevDay.org
 
Introduction to test programming
Introduction to test programmingIntroduction to test programming
Introduction to test programming
openfinanceDev
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for Distro
Paul Boos
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdf
Eric Selje
 
Devday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvuDevday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvu
Phat VU
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
guestebde
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2
Rosie Sherry
 
Automated tests
Automated testsAutomated tests
Automated tests
Damian Sromek
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
Steven Casey
 

Similar to Win at life with unit testing (20)

assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsIntegration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
 
Testing 101
Testing 101Testing 101
Testing 101
 
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
 
Introduction to test programming
Introduction to test programmingIntroduction to test programming
Introduction to test programming
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for Distro
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdf
 
Devday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvuDevday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvu
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2
 
Automated tests
Automated testsAutomated tests
Automated tests
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 

More from markstory

Dependency injection in CakePHP
Dependency injection in CakePHPDependency injection in CakePHP
Dependency injection in CakePHP
markstory
 
Safer, More Helpful CakePHP
Safer, More Helpful CakePHPSafer, More Helpful CakePHP
Safer, More Helpful CakePHP
markstory
 
CakePHP - The Road Ahead
CakePHP - The Road AheadCakePHP - The Road Ahead
CakePHP - The Road Ahead
markstory
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
markstory
 
CakePHP mistakes made 2015
CakePHP mistakes made 2015CakePHP mistakes made 2015
CakePHP mistakes made 2015
markstory
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
markstory
 
PHP WTF
PHP WTFPHP WTF
PHP WTF
markstory
 
CakePHP 3.0 and beyond
CakePHP 3.0 and beyondCakePHP 3.0 and beyond
CakePHP 3.0 and beyond
markstory
 
CakePHP mistakes made confoo 2015
CakePHP mistakes made confoo 2015CakePHP mistakes made confoo 2015
CakePHP mistakes made confoo 2015
markstory
 
CakePHP mistakes made
CakePHP mistakes madeCakePHP mistakes made
CakePHP mistakes made
markstory
 
Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014
markstory
 
Road to CakePHP 3.0
Road to CakePHP 3.0Road to CakePHP 3.0
Road to CakePHP 3.0
markstory
 
Performance and optimization
Performance and optimizationPerformance and optimization
Performance and optimization
markstory
 
OWASP Top 10 2013
OWASP Top 10 2013OWASP Top 10 2013
OWASP Top 10 2013
markstory
 
CakePHP the yum & yuck
CakePHP the yum & yuckCakePHP the yum & yuck
CakePHP the yum & yuck
markstory
 
Introduction to Twig
Introduction to TwigIntroduction to Twig
Introduction to Twig
markstory
 
Owasp top 10
Owasp top 10Owasp top 10
Owasp top 10
markstory
 
Simple search with elastic search
Simple search with elastic searchSimple search with elastic search
Simple search with elastic search
markstory
 
Making the most of 2.2
Making the most of 2.2Making the most of 2.2
Making the most of 2.2
markstory
 
Intro to continuous integration
Intro to continuous integration Intro to continuous integration
Intro to continuous integration
markstory
 

More from markstory (20)

Dependency injection in CakePHP
Dependency injection in CakePHPDependency injection in CakePHP
Dependency injection in CakePHP
 
Safer, More Helpful CakePHP
Safer, More Helpful CakePHPSafer, More Helpful CakePHP
Safer, More Helpful CakePHP
 
CakePHP - The Road Ahead
CakePHP - The Road AheadCakePHP - The Road Ahead
CakePHP - The Road Ahead
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
CakePHP mistakes made 2015
CakePHP mistakes made 2015CakePHP mistakes made 2015
CakePHP mistakes made 2015
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
 
PHP WTF
PHP WTFPHP WTF
PHP WTF
 
CakePHP 3.0 and beyond
CakePHP 3.0 and beyondCakePHP 3.0 and beyond
CakePHP 3.0 and beyond
 
CakePHP mistakes made confoo 2015
CakePHP mistakes made confoo 2015CakePHP mistakes made confoo 2015
CakePHP mistakes made confoo 2015
 
CakePHP mistakes made
CakePHP mistakes madeCakePHP mistakes made
CakePHP mistakes made
 
Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014
 
Road to CakePHP 3.0
Road to CakePHP 3.0Road to CakePHP 3.0
Road to CakePHP 3.0
 
Performance and optimization
Performance and optimizationPerformance and optimization
Performance and optimization
 
OWASP Top 10 2013
OWASP Top 10 2013OWASP Top 10 2013
OWASP Top 10 2013
 
CakePHP the yum & yuck
CakePHP the yum & yuckCakePHP the yum & yuck
CakePHP the yum & yuck
 
Introduction to Twig
Introduction to TwigIntroduction to Twig
Introduction to Twig
 
Owasp top 10
Owasp top 10Owasp top 10
Owasp top 10
 
Simple search with elastic search
Simple search with elastic searchSimple search with elastic search
Simple search with elastic search
 
Making the most of 2.2
Making the most of 2.2Making the most of 2.2
Making the most of 2.2
 
Intro to continuous integration
Intro to continuous integration Intro to continuous integration
Intro to continuous integration
 

Win at life with unit testing

  • 1. Win at Life with Unit Testing. by Mark Story
  • 2. Who is this goofball Art college graduate that needed to make money. CakePHP core contributor for 2.5 years. Developer of DebugKit, ApiGenerator and several other plugins. Lead front end developer at FreshBooks
  • 3. Can unit testing make me awesome?
  • 5. Why write tests? Helps ensure things that did work, still do. Helps reduce time it takes to fix new defects. Helps you plan a design, showing you where it might be complicated or overly coupled. Living documentation.
  • 6. ... Catch issues earlier. Increased developer confidence. Automated killer robots.
  • 7. What to test? Code that keeps you up at night. Code that involves real money. Code that has broken before. Code that is tedious to test manually.
  • 9. Unit Tests Testing the smallest parts of your application in isolation. Often testing single methods or single functions. Generally uses many mocks. Really useful when doing Test driven development.
  • 10. Functional Tests Tests pieces working well together. Test top level objects to ensure all their guts are working together. Tests hitting database fixtures are often functional tests. Functional tests run slower, but use more active code.
  • 11. Challenges of testing Time. It takes time to write tests. But it takes more time to fix the same bugs later multiple times. Only shows the presence of issues, not the absence. Only catches errors you have tests for.
  • 12. Benefits of testing Find problems earlier. Can be automated, robots are helpful. Less manual testing. Easier to ensure requirements are met. Unicorns.
  • 13. The End. Of the part where I extol the winsauce tests can bring.
  • 15. Mocks and test doubles Writing isolated tests is hard. Mock objects make it easier. Mocks help ensure your objects are touching other objects in the right places. Mocks help you stub out behaviour before you write the real deal.
  • 16. Can I use a mock for: Global functions? Stuff not in functions?
  • 17. No.
  • 18. When to use mocks When talking to the outside world. Email. Webservices (Twitter, Paypal, YouTube). Writing files to disk. Writing to the database.
  • 19. ... When you want to ensure two objects are working together properly. When you do want to isolate problems.
  • 20. Mocking your code Make sure dependencies can be replaced at runtime. Constructor injection. Factory methods. Setter methods.
  • 21. Constructor Injection Accept objects your object depends on in the constructor. Jam mocks in when testing.
  • 22. Factory Factory Factory Factory methods can be overridden in subclasses to return mocks.
  • 23. Setter method Allows post construction modification of internal dependencies.
  • 24. Mocks in the house Mocks can be critical of a test subject. Mocks and stub out dangerous components, or methods.
  • 25. Critical mocking Critic mocks check that other objects touch them correctly.
  • 26. Stub danger. You can stub methods that send headers or touch the outside world.
  • 27. Stub expensive stuff. Mocks can be used to stub network resources or expensive to fetch results.
  • 28. In conclusion Mocks help make tests run faster, and require less setup & teardown. They allow you to write true unit tests.
  • 29. The End. (of the part where I blabber about mocks)
  • 30. Automated Killer Robots test automation for squishy humans.
  • 31. Automated testing. Tests that are never run, are as good as deleted. Build servers to the rescue!
  • 32. Hudson Hudson is a continuous integration server built in Java. Has a great plugin community. Can send emails, Jabber and give pithy Chuck Norris quotes.
  • 33. ... Can be configured to run on a schedule or post commit. Integrates well with SVN and there is a GIT plugin too.
  • 34. Typical Hudson setup Run tests on each commit/push. Run all tests again each night, incase there was a slow day. Nightly builds are also a good time to run code coverage builds.
  • 35. Setting Hudson up Go to http://hudson-ci.org wget http://hudson-ci.org/latest/hudson.war java -jar hudson.war
  • 41. The End. For real this time.