SlideShare a Scribd company logo
TDD*
Alex Kavanagh
@ajkavanagh
*Test Driven Development
Why?
–Michael Sinz
“Programming is like sex …
one mistake and you have to support it
for the rest of your life.”
–Steve M. McConnell
“The problem with quick and dirty
is that
Dirty
remains long
after the quick has been
forgotten.”
–John Woods
“Always code as if the guy
who ends up maintaining your code
will be a
violent psychopath
who knows where you live.”
What is TDD?
TDD python ne-april-2014
TDD python ne-april-2014
Write Test
Run the test
and see it fail
$ nosetests -v websandpym/tests/test_auth_utils.py:Utils_Tests.test__generate_jti_claim
test__generate_jti_claim (websandpym.tests.test_auth_utils.Utils_Tests) ... ERROR
======================================================================
ERROR: test__generate_jti_claim (websandpym.tests.test_auth_utils.Utils_Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/alex/unison-root/Projects/Websand/instances/websand-pym/websand-pym/websandpym/tests/test_auth_utils.py",
line 101, in test__generate_jti_claim
claims = auth_utils._generate_jti_claim()
nose.proxy.AttributeError: 'module' object has no attribute '_generate_jti_claim'
-------------------- >> begin captured logging << --------------------
passlib.utils.compat: DEBUG: loaded lazy attr 'SafeConfigParser': <class 'configparser.ConfigParser'>
passlib.utils.compat: DEBUG: loaded lazy attr 'NativeStringIO': <class '_io.StringIO'>
passlib.utils.compat: DEBUG: loaded lazy attr 'BytesIO': <class '_io.BytesIO'>
passlib.registry: DEBUG: registered 'bcrypt' handler: <class 'passlib.handlers.bcrypt.bcrypt'>
passlib.registry: DEBUG: registered 'pbkdf2_sha256' handler: <class 'passlib.handlers.pbkdf2.pbkdf2_sha256'>
--------------------- >> end captured logging << ---------------------
----------------------------------------------------------------------
Ran 1 test in 0.002s
FAILED (errors=1)
Write some
code
Run test
again
$ nosetests -v websandpym/tests/test_auth_utils.py:Utils_Tests.test__generate_jti_claim
test__generate_jti_claim (websandpym.tests.test_auth_utils.Utils_Tests) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.014s
OK
…until the test passes
then …
Refactor
TDD python ne-april-2014
In summary
TDD python ne-april-2014
TDD and Python
Learning by doing … (scary live demo)
(to play along: https://github.com/ajkavanagh/PythonNE-TDD-Example)
Where to next?
http://pythontesting.net/start-here/
Topics to look at
Mocking
End2End Testing (for web frameworks)
BDD
etc. (it’s a big field …)
–codebetter.com
“Unit Tests confirm we have written the code
right [sic].
Acceptance Tests that we built the right
software.”
–Kent Beck
“TDD doesn’t drive good design. TDD gives
you immediate feedback about what is likely to
be bad design.”
Code Dojo Ideas
1. Write a module that ‘manages’ Polar coords. Allow
transformations between cartesian and polar coords.
2. Write a module that counts frequencies of words
passed to. Extra credit - remember previous counts
and add to them.
3. Implement a really simple shopping cart. Extra credit
- add a discounting system.
4. Implement a Bank Account class that can transfer
money between accounts, have account limits.
Image Credits
http://www.cfn308bestnetwork.com/sites/default/files/writing.gif
http://2.bp.blogspot.com/_4OIF7pROmHM/SwV3hzmTaAI/AAAAAAAAAe8/wVyXyHhMrT0/s1600/54208__468x_failed-exam-answers-22.jpg
http://allantyoung.com/wp-content/uploads/2008/11/matrixcode.jpg
http://icons.iconarchive.com/icons/icons-land/vista-multimedia/256/Play-Mode-Repeat-All-Hot-icon.png
http://coltandsage.com/wp-content/uploads/2013/12/rinse-repeat.jpg
http://carlosble.com/downloads/tdd.png
http://www.ben-morris.com/wp-content/library/refactoring-vs-rewriting.gif

More Related Content

PPTX
TDD er død. Lenge leve TDD!
PDF
Test Driven Development in Python
PPTX
Insoft training day_1
PPTX
Mocking in python
PPTX
Exceptions: Why, When, How and Where!
KEY
Overview of Testing Talks at Pycon
ODP
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
PDF
Day1 - TDD (Lecture SS 2015)
TDD er død. Lenge leve TDD!
Test Driven Development in Python
Insoft training day_1
Mocking in python
Exceptions: Why, When, How and Where!
Overview of Testing Talks at Pycon
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Day1 - TDD (Lecture SS 2015)

What's hot (20)

PPTX
TDD & Refactoring
PPTX
The problem with tdd
PPTX
Go/Ruby/Java: What's next?
PDF
TDD, the way to better software | Dan Ursu | CodeWay 2015
PDF
JavaScript frontend testing from failure to good to great
PDF
Test Driven Development en Go con Ginkgo y Gomega
PPT
Lessons learned on software testing automation
PPT
Los diez mandamientos de TDD
PDF
Introduction to Continuous Delivery
PPTX
Obejct Oriented SCM - OOSCM
PPTX
Test-Driven Development
ODP
Coderetreat @AgileFinland Tampere 2014 11 12
ODP
@LinkingNote annotation in YATSPEC
PDF
TDD - Designing with Expectations, not Implementations
PDF
Unit testing (workshop)
PDF
Is this how you hate unit testing?
PDF
TDD and Simple Design Workshop - Session 1 - November 2018
PPT
The ten commandments of TDD
PDF
Coderetreat @Sibiu 2012 08 18
PDF
Chaos Engineering Talk at DevOps Days Austin
TDD & Refactoring
The problem with tdd
Go/Ruby/Java: What's next?
TDD, the way to better software | Dan Ursu | CodeWay 2015
JavaScript frontend testing from failure to good to great
Test Driven Development en Go con Ginkgo y Gomega
Lessons learned on software testing automation
Los diez mandamientos de TDD
Introduction to Continuous Delivery
Obejct Oriented SCM - OOSCM
Test-Driven Development
Coderetreat @AgileFinland Tampere 2014 11 12
@LinkingNote annotation in YATSPEC
TDD - Designing with Expectations, not Implementations
Unit testing (workshop)
Is this how you hate unit testing?
TDD and Simple Design Workshop - Session 1 - November 2018
The ten commandments of TDD
Coderetreat @Sibiu 2012 08 18
Chaos Engineering Talk at DevOps Days Austin
Ad

Viewers also liked (6)

PPTX
TDD with RSpec
PDF
Testing with Rspec 3
PPTX
RSpec: What, How and Why
PDF
Tdd with rspec.md
PDF
RSpec & Rails, an introduction
PDF
RSpec 2 Best practices
TDD with RSpec
Testing with Rspec 3
RSpec: What, How and Why
Tdd with rspec.md
RSpec & Rails, an introduction
RSpec 2 Best practices
Ad

Similar to TDD python ne-april-2014 (20)

PDF
TDD super mondays-june-2014
PPTX
An Introduction to unit testing
PDF
Tdd is not about testing
PPTX
Test-Driven Development In Action
PPTX
TDD Best Practices
PPTX
Building unit tests correctly with visual studio 2013
PDF
DSR Testing (Part 1)
PDF
Test Driven Development
ODP
Unit testing-patterns
PPTX
Test driven development in .Net - 2010 + Eclipse
PPTX
Tdd is not about testing (OOP)
PDF
des mutants dans le code.pdf
PDF
Bdd and-testing
PDF
Behaviour Driven Development and Thinking About Testing
 
PDF
TDD Workshop UTN 2012
PDF
Python and test
PDF
How to complement TDD with static analysis
PDF
Tdd in practice
PPTX
Practical unit testing tips
PDF
Testacular
TDD super mondays-june-2014
An Introduction to unit testing
Tdd is not about testing
Test-Driven Development In Action
TDD Best Practices
Building unit tests correctly with visual studio 2013
DSR Testing (Part 1)
Test Driven Development
Unit testing-patterns
Test driven development in .Net - 2010 + Eclipse
Tdd is not about testing (OOP)
des mutants dans le code.pdf
Bdd and-testing
Behaviour Driven Development and Thinking About Testing
 
TDD Workshop UTN 2012
Python and test
How to complement TDD with static analysis
Tdd in practice
Practical unit testing tips
Testacular

Recently uploaded (20)

PPTX
Essential Infomation Tech presentation.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Introduction to Artificial Intelligence
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
history of c programming in notes for students .pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Understanding Forklifts - TECH EHS Solution
Essential Infomation Tech presentation.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Introduction to Artificial Intelligence
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
VVF-Customer-Presentation2025-Ver1.9.pptx
history of c programming in notes for students .pptx
Wondershare Filmora 15 Crack With Activation Key [2025
wealthsignaloriginal-com-DS-text-... (1).pdf
Digital Strategies for Manufacturing Companies
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Which alternative to Crystal Reports is best for small or large businesses.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Upgrade and Innovation Strategies for SAP ERP Customers
Understanding Forklifts - TECH EHS Solution

TDD python ne-april-2014