tdd super mondays-june-2014
TRANSCRIPT
![Page 1: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/1.jpg)
TDD*Alex Kavanagh @ajkavanagh
*Test Driven Development
![Page 2: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/2.jpg)
![Page 3: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/3.jpg)
–Michael Sinz
“Programming is like sex … one mistake and you have to support it
for the rest of your life.”
![Page 4: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/4.jpg)
–Steve M. McConnell
“The problem with quick and dirty is that Dirty
remains long after the quick has been
forgotten.”
![Page 5: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/5.jpg)
Agile with Scrum or Kanban
![Page 6: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/6.jpg)
![Page 7: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/7.jpg)
![Page 8: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/8.jpg)
Continuous Integration
& Deployment
![Page 9: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/9.jpg)
Reducing pressure to ship
![Page 10: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/10.jpg)
If you don’t automate it,
it won’t happen!
![Page 11: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/11.jpg)
What is TDD?
![Page 12: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/12.jpg)
![Page 13: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/13.jpg)
Write Test
![Page 14: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/14.jpg)
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)
![Page 15: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/15.jpg)
Write some code
![Page 16: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/16.jpg)
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
![Page 17: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/17.jpg)
…until the test passes
![Page 18: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/18.jpg)
then …
![Page 19: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/19.jpg)
Refactor
![Page 20: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/20.jpg)
![Page 21: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/21.jpg)
In summary
![Page 22: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/22.jpg)
![Page 23: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/23.jpg)
TDD and Python
![Page 24: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/24.jpg)
Python Testing
• UnitTest
• Nose
• py.test
• sure
![Page 25: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/25.jpg)
unittest
• “Inspired” by JUnit
• Has fixtures, test cases, suites and a test runner.
• Uses ‘assert <something’ or
• self.<assert_method>(params…)
• to do assertions.
![Page 26: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/26.jpg)
nose• Extends unittest - to make testing easier
• Lots of plugins (not all Python3 compatible).
• Basically:
• finds tests
• Runs them
• Gives nicer outputs that unittest.
• https://nose.readthedocs.org/en/latest/
![Page 27: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/27.jpg)
py.test
• Also a test-runner!
• pytest can run nose, unittest and doctest style test suites
• Very flexible.
• http://pytest.org/latest/contents.html
![Page 28: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/28.jpg)
sure• A DSL for writing tests in Python
• Inspired by should.js
• Write this:
• expect(something).to.be.equal(4)
• something.should.be.equal.to(4)
• Instead of this:
• self.assertEqual(something, 4)
![Page 29: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/29.jpg)
Where to next?http://pythontesting.net/start-here/
![Page 30: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/30.jpg)
TDD and Javascript
Well, actually CoffeeScript as it’s nicer for tests :)
![Page 31: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/31.jpg)
Yes, coffee script :)describe('User', function(){ describe('#save()', function(){ it('should save without error', function(done){ var user = new User('Luna'); user.save(function(err){ if (err) throw err; done(); }); }) }) })
describe ‘User’, -‐> describe ‘#save’, -‐> it ‘should save without error’, (done) -‐> user = new User(‘Luna’) user.save (err) -‐> if(err) throw err done()
![Page 32: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/32.jpg)
JS Testing• Test your JS in the browser (phantomjs, et al.)
• Writing node.js? Test your node.js code (mocha, jasmine, et al.)
• AngularJS? EmberJS? (<other> JS framework). Test your code in various browsers & node.js using Karma
• End-2-End testing - bootstrap your app, with the browser and have e2e tests.
![Page 33: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/33.jpg)
JS Testing Tools
• Karma - http://karma-runner.github.io
• A simple tool that allows you to execute JavaScript code in multiple real browsers.
• Mocha - http://visionmedia.github.io/mocha/
• Asynchronous testing fun!
• Should.js, expect.js, chai - DSL style assertion libraries.
![Page 34: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/34.jpg)
Things I didn’t coverMocking
BDD (but hopefully Philip did!)
Continuous Integration
Continuous Delivery
…but you have to have an automated test system to even begin to attempt these.
![Page 35: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/35.jpg)
–codebetter.com
“Unit Tests confirm we have written the code right [sic].
Acceptance Tests that we built the right software.”
![Page 36: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/36.jpg)
–Kent Beck
“TDD doesn’t drive good design. TDD gives you immediate feedback about what is likely to
be bad design.”
![Page 37: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/37.jpg)
–John Woods
“Always code as if the guy who ends up maintaining your code
will be a violent psychopath
who knows where you live.”
![Page 38: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/38.jpg)
@ajkavanagh
![Page 39: TDD super mondays-june-2014](https://reader034.vdocuments.net/reader034/viewer/2022052603/55d37488bb61eb12738b46e2/html5/thumbnails/39.jpg)
Image Creditshttp://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 http://www.repmanblog.com/wp_app/wp-content/uploads/2014/03/why-1.jpg http://www.lynnecazaly.com.au/storage/agile%20manifesto%20screenshot.jpg?__SQUARESPACE_CACHEVERSION=1394163978554 http://www.versionone.com/images/agile101/agile_development_value_proposition.gif http://clickhowto.com/wp-content/uploads/2013/01/Agile-methodologies.jpg http://blog.crisp.se/wp-content/uploads/2013/02/continuous-delivery-deployment-sm.jpg http://gb.fotolibra.com/images/previews/120351-a-pressure-gauge-showing-high-pressure.jpeg http://www.layeredthoughts.com/wp-content/uploads/2012/09/200712_regex_no_manual_labor.jpg https://cdn.tutsplus.com/net/uploads/legacy/767_testDrivenDev/tdd.png http://www.wpclipart.com/signs_symbol/words/thank_you/Thank_You_note_big_outline_T.png