Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Unit testing in python
Search
Gabriel Falcão
February 06, 2012
Programming
730
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
More Decks by Gabriel Falcão
See All by Gabriel Falcão
Testing in Django
gabrielfalcao
8
730
Other Decks in Programming
See All in Programming
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
580
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
200
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
200
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
170
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
530
仕様駆動開発の消費期限
watany
8
4.4k
Built Our Own Background Agent at LayerX
layerx
PRO
9
4.9k
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
480
Google Apps Script で Ruby を動かす
kawahara
0
130
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
240
「人を評価する AI」の設計と実装
ryoyanara
0
160
Featured
See All Featured
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
610
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
430
A Modern Web Designer's Workflow
chriscoyier
698
190k
We Are The Robots
honzajavorek
0
290
Between Models and Reality
mayunak
4
380
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
430
Are puppies a ranking factor?
jonoalderson
1
3.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.2k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
460
Making Projects Easy
brettharned
120
6.7k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
670
Transcript
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