Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Train to test

455 views

Published on

Presented at CVREG on 3/13/2012.
http://www.cvreg.org/2012/3/7/march-meeting-m-scott-ford-and-train-to-test

Abstract

Many pundits would have you believe that the switch from a developer to a developer tester is just a bit that you can flip in your head. I claim that this is false.

While testing is something we all know that we should be doing more of, many of us are struggling to figure out how. Chances are you’re somewhere in between a developer that never tests and one that tests every time s/he should. And I bet that you’re unhappy with where you are at, and you’d like to figure out how to get closer to where you want to be.

Using the metaphor of going to the gym, I’ll go over some exercises that you can perform. Some of these exercises you’ll be able to perform on your current projects, while others you may want to try out on a toy or side project first. These should help you feel better about how often you test, and it might be easier than losing a few pounds.

Published in: Technology, Education
  • Be the first to comment

Train to test

  1. 1. TRAIN TO TEST M. SCOTT FORD
  2. 2. CONTACT INFOSenior Developer with Rails Dog, LLCChief Code Monkey with Corgibytes, LLCmscottford.comgithub.com/mscottford@mscottfordscott@mscottford.com
  3. 3. WHY I GOT STARTED
  4. 4. PROJECTSLibrary automation Law enforcementExperimental aircraft Public API for email hostingLibrary self checkout More law enforcementReal property management Content managementRailroad traffic control E-CommerceBack office automation
  5. 5. MISSION CRITICAL AND SAFETY CRITICALSafety critical: a software failure may result in the loss of someone’s lifeMission critical: a software failure may result in the loss of someone’s money
  6. 6. MY CONCLUSIONEvery project is critical.Critical projects should betested.
  7. 7. MY CONCLUSIONEvery project is critical.Critical projects should betested.Every project should betested.
  8. 8. WHY TRAINING?
  9. 9. TESTING AND EXERCISE HAVE A LOT IN COMMONGetting started is intimidatingImproves healthDeveloping the habit is hardWork now prevents problemslaterThere’s always room forimprovement
  10. 10. EXERCISE #1BUYING A GYM MEMBERSHIP
  11. 11. ADD RSPEC TO YOUR GEMFILE$ gem install bundler# ./Gemfilesource :rubygemsgem ‘rspec’$ bundle
  12. 12. CREATE SPEC DIRECTORY$ mkdir spec# ./spec/spec_helper.rbrequire ‘demo’
  13. 13. CREATE YOUR FIRST SPEC# ./spec/demo_spec.rbrequire ‘spec_helper’describe Demo do it ‘should exist’ do endend
  14. 14. RUN RSPEC$ rspec.Finished in 0.00034 seconds1 example, 0 failures
  15. 15. EXECISE #2 CREATE GOALS
  16. 16. LET’S TALK ABOUT MEASUREMENTSTest Coverage Body Mass IndexTC = Tested LOC / LOC BMI = mass / height2Size of your project dictates Your age dictates what’swhat’s reasonable reasonableToo much energy on test It’s possible to go to the gymcoverage is not productive too much
  17. 17. WHAT GOAL SHOULD I SETSMART goals are bestSpecific Measurable Attainable Reasonable and Timely.Example:By January 2013 test coverage will have increased by 5 percentagepoints to 12%.Source: http://en.wikipedia.org/wiki/SMART_criteria
  18. 18. EXERCISE #3 BUY A SCALE
  19. 19. ADD SIMPLECOV TO YOUR GEMFILE# ./Gemfilesource :rubygemsgem ‘rspec’gem ‘simplecov’$ bundle
  20. 20. ADD SIMPLECOV TO SPEC_HELPER.RB# ./spec/spec_helper.rbrequire simplecovSimpleCov.startrequire demo
  21. 21. RUN RSPEC$ rspec.Finished in 0.00043 seconds1 example, 0 failuresCoverage report generated for RSpec to ./coverage.2 / 3 LOC (66.67%) covered.
  22. 22. EXERCISE #4GET ON THE DAMN TREADMILL
  23. 23. WRITE MORE TESTSAnytime you find yourself asking these questions, consider writing atest What happens when I pass nil to this method? How does this method respond if a dependent method raises an exception? Do those 30 lines that I wrote actually work? (How about the 30 I haven’t written yet?)
  24. 24. THIS IS A PERFECTLY VALID TESTdescribe Demo do it ‘should not crashed when created with nil’ Demo.new(nil) endend
  25. 25. PRACTICE NOT USING THE DEBUGGERWhen you start a debugging session you have a question that you’retrying to answer.Consider whether or not it’s possible to formalize that question in atest.If you find yourself repeating the debugging session more than twice,then find a way to formalize the question.
  26. 26. EXERCISE #5 STAYING FOCUSED
  27. 27. THINGS TO KEEP IN MINDIt’s okay that you’re struggling. There are others out there like you.It’s okay that you’re not testingevery single line of code. You are not alone.It’s okay that you want to give Sticking with it is hard, butup. worthwhile.It’s okay that you feel guiltyabout not testing enough.
  28. 28. PHOTO CREDITSAll photos are licensed under a Created Commons “Apples & Oranges - They Don’t Compare” bylicense that requires attribution. In order of appearance: TheBusyBrain http://www.flickr.com/photos/thebusybrain/2492945625/“Brompton World Championship - Sprint Finish” by JonSpooner “out with the old, in with the new” by KetuGajjarhttp://www.flickr.com/photos/johnspooner/2899977876/ http://www.flickr.com/photos/ketugajjar/5406134368/“Young & Old, Let’s Get it On” by AlphaTangoBravo / “FOCUS on the GOAL !” by GHOURI !Adam Baker http://www.flickr.com/photos/geekydevil/2707101111/http://www.flickr.com/photos/atbaker/447122802/ “scale_zero” by dsearls“Sailor participates in Marine Corps Combat Fitness http://www.flickr.com/photos/docsearls/5500725788/Test.” by Official U.S. Navy Imagery “New Year’s Resolution: 36/365” by SashaWhttp://www.flickr.com/photos/usnavy/5590118536/ http://www.flickr.com/photos/sashawolff/3171917389/“Danbo Goes to the Gym” by chauromano “Focus” by toolstophttp://www.flickr.com/photos/chauromano/5786885286/ http://www.flickr.com/photos/toolstop/4546017269/
  29. 29. CONTACT INFOSenior Developer with Rails Dog, LLCChief Code Monkey with Corgibytes, LLCmscottford.comgithub.com/mscottford@mscottfordscott@mscottford.com

×