quid est testing?

nick quaranto

5th year SE & CS major

ruby fanatic

bills fan


@qrush

litanyagainstfear.com

what is testing?

not:

refreshing

compiling

for someone else to do

empirical investigation conducted to provide stakeholders with information about the quality of the product or service under test

wikipedia

tl;dr

the process of executing a program or system with the intent of finding errors

the art of software testing

closer...

clean code that works

acceptance testing

integration testing

functional testing

unit testing

acceptance testing

integration testing

functional testing

unit testing

what is a unit?

programmer tests

define what it means for the code to work

why should I test?

predictability

  • have a process
  • know you are finished

tighter feedback loops

  • running code informs decisions
  • learn lessons faster

dependability

  • build trust
  • know immediately when you break something

loose coupling

  • easy to test
  • not just a buzzword

how do you test?

  • setup
  • exercise
  • verification
  • teardown

same process for any language

test methods run in isolation

let's do some ruby

require 'test/unit'
class BillsPlayerTest < Test::Unit::TestCase
  def test_to_is_a_tad_bit_hyped
  end
end

setup

terrell_owens = BillsPlayer.new

exercise

terrell_owens.overpaid?

verification

assert

other assertions

assert_equal "wide receiver",
  terrell_owens.position

assert_not_nil terrell_owens.number

assert_raises InterceptionError do
  terrell_owens.miss_route!
end
class BillsPlayerTest < Test::Unit::TestCase
  def test_to_is_a_tad_bit_hyped
    terrell_owens = BillsPlayer.new
    assert terrell_owens.overpaid?
  end
end
class BillsPlayerTest < Test::Unit::TestCase
  def setup
    @terrell_owens = BillsPlayer.new
  end

  def test_to_is_a_tad_bit_hyped
    assert @terrell_owens.overpaid?
  end

  def teardown
    # bills lose, again :[
  end
end

so what?

  • production errors due to uncomprehensive tests
  • often done after the code is written
  • if not automated, not preformed frequently
  • and so on...

test driven development

you, the developer, write the tests!

write tests before implementation

new code only when an automated test fails

take small steps

the process

  • write a test
  • watch it fail
  • write just enough code to make it pass

let's do this

feedback loop

  • red
  • green
  • refactor

refactor

  • eliminate duplication
  • rename
  • single responsibility
  • and so on...

tdd is about design

design is a process, not a phase

think about the interface before implementation

when do I test?

TATFT

the drawbacks

all walk, no talk

easier with a pair

team buy-in

some thoughts...

it's ok not to test!

testing vs. spiking

dependencies

  • fakes
  • stubs
  • mocks

find a coop (or job) that helps you test

ask about policies on testing

TATFT

thanks!

  • you
  • thoughtbot
  • david astels
  • ben mabey
  • bryan liles