Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Unit testing in python
Search
Gabriel Falcão
February 06, 2012
Programming
740
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Unit testing in python
motivation, techniques and tools
Gabriel Falcão
February 06, 2012
Transcript
41 slides
Unit testing motivation, techniques and tools
Past •Tests were written after the code was “ready” •Mocks,
Stubs, are also an old concept: isolate modules •Microsoft, Sun and other huge software companies were using since... ever
Hey wait... Microsoft Testing after written? +
coincidence?
Present •Kent Back changed the world •Google, Facebook, [your badass
company here] doing •Mocks, Stubs, now are less heavily used
Why is it cool ? •Automagic refactoring •Modules are isolated
•Code is cleaner •Modules are isolated •No more fear when changing code that is too important •They run just so fast •White box
Wait.... white box?!
White box •Comes from hacking/security vocabulary •The developer knows the
codebase in depth •Test relies on internal calls
Test-driven development How to start it
Baby steps
Baby steps •Don’t write the whole thing at once •The
next step will come naturally •Small units of code •The name is cute
The Mantra Red (1) Green (2) Refactor (3)
... in other words
YAGNI YOU AIN’T GONNA NEED IT ...at least for now.
YAGNI
YAGNI Focus on what you need to achieve now don’t
try to predict the future
Python Past/present/future?
Python - Past •unittest and unittest2 •class-based •camel case •overcomplicated
•the community wasn’t really into it •... so we didn’t have many libraries BORING...
Python - Past
None
Python - Present •Nose — •DSLs are growing and becoming
more popular •it is becoming fun to write tests •so that we’ll want to write more and more ROBUST CODE
Python - Present •Easier to write •conventions instead of classes
•libraries leveraging mocks and stubs
Old-school mocking and asserting
But now we are hipsters
and cool libraries does the hard job
What about stubs? •They’re just like mocks •But doesn’t have
behavior (no methods, just info)
What about stubs?
Future?!
Future?!
Future?!
Future?!
Django let’s have some fun
How it is •The default test support uses unittest2 •or
doctests •don’t separate between unit, functional, etc •which leverages having very slow suites •doesn’t provide support for isolation •kinda focused on black box
Unclebob •per app tests (unit, functional, integration) •isolate the database
so it fails if your test tries to use it •discover tests automagically
Unclebob http://bit.ly/woTgXq
testing huge views
None
None
the idea is simple
move logic into objects, testing each unit of logic separately
links •http://readthedocs.org/docs/nose/en/latest/ •http://github.com/gabrielfalcao/sure •http://github.com/gabrielfalcao/unclebob
More Decks by Gabriel Falcão
See All by Gabriel Falcão
Testing in Django
gabrielfalcao
8
750
Other Decks in Programming
See All in Programming
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
280
SODA - FACT BOOK(EN)
sodainc
1
310
Compiling Your Language to WasmGC & Friends
tanishiking
1
1k
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
120
高速開発を止めずに 性能を上げる Flyleのシステム刷新と改善の歴史
azihsoyn
0
120
読みやすい!と評判(?)の発表の準備にかける私のこだわり
shoheimitani
0
170
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
210
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
490
AIコーディング時代のKotest ユニットテストから APIレベルの仕様固定化テストへ
ooga04
0
360
エージェントの管理もエージェントに – herdr-core と自作バックログで作る司令塔 –
nearme_tech
PRO
2
190
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
6.4k
Lean で手続き的プログラム の証明が書けるようになった
inoueasei
11
6.2k
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.3k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Rails Girls Zürich Keynote
gr2m
96
14k
How GitHub (no longer) Works
holman
316
150k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
61k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
590
Amusing Abliteration
ianozsvald
1
410
Technical Leadership for Architectural Decision Making
baasie
4
660
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.3k
Evolving SEO for Evolving Search Engines
ryanjones
0
380